[x3d-public] X3DJSAIL XML output error I think. nested ' apostrophecharacters?

Don Brutzman brutzman at nps.edu
Mon Feb 27 09:41:50 PST 2017


[summary: continuing analysis of string escaping across file formats and language bindings]

On 2/27/2017 2:50 AM, yottzumm at gmail.com wrote:
> I’ll have to figure out what to do for \"  and "  in DOM SFStrings so I’m doing the right thing.  I’m currently replacing them with " in my JavaSerializer.js.  Not sure if the main Java program should contain XML entities, or if that should be a feature of X3DJSAIL.  Hopefully, you are handling &, < and > in SFStrings and MFstrings as well (hint).  I should probably let X3DJSAIL convert " to " if possible, at least in SFStrings.  We shall see if my DOM MFString handler passes mustard (do I have to check for " ", " " and " " as well?)—the handler probably will since we come from JSON originally.

aha, yes indeed.  as a temporary improvement in current output:

stringX3D.append(" reference='").append(
	SFStringObject.toString(getReference())
			.replace("&","&")
			.replace("<","<")
			.replace(">",">")
			.replace("'","'")
			.replace("\"","\\"")).append("'");

this kind of approach won't handle quotation marks in MFString output properly, since each string is quoted.

this kind of task might occasionally needed by Java programmers, not just during .x3d file serialization.

so i will work on exposing this cleanup by adding a matched set of utility methods to SFStringObject and MFStringObject, perhaps toStringEscaped() or somesuch.

we will then need to test out our conversion chains with a few example scenes.

>I have to remember that I’m working with DOM and not JSON or XML.

... or XSLT.  amen brother.

> I will also readdress what is happening in SourceCode with single quotes.  I think right now, the Java doesn’t compile, so there’s some work on my end.  Right now, the monstrosity looks like:
>
>
>
>                 } else if (element.childNodes.hasOwnProperty(cn) && node.nodeType == 4) {
>
>                         str += "                "+element.nodeName+n+'.setSourceCode("'+node.nodeValue.replace(/"/g, '\\"').replace(/\\n'/, "\\n'").split("\r\n").join('\\n\"+\n\"')+'");\n';

With changes such as the block above, you shouldn't have to worry about anything but parsing and saving text properly.  No escaping should be needed when setting, it is only appropriate when creating file output.

> Oh, lovely, I just discovered appendSourceCode() that should help.  Or I will use Array.map to do the substitutions after first splitting along newlines.

so hopefully the monstrosity is shrinking and disappearing!  our success goal is to make usage simple, when possible...  it is worth regular consideration that X3DJSAIL goal is ease of use, so problems & difficulties are worth cleaning up at that level if possible.

and so, yes if you are not finding an appropriate/simple utility method, such as appendSourceCode(), then you've found a good candidate to add.

thanks for continuing suggestions.

all the best, Don
-- 
Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman



More information about the x3d-public mailing list