[X3D-Public] Should MFString (and SFString) in XML encoding use backslashes?

Braden McDaniel braden at endoframe.com
Tue Jul 19 07:49:08 PDT 2011

On Tue, 2011-07-19 at 08:21 +0200, Michalis Kamburelis wrote: 
> Hi,
> While testing new X3D XML output in view3dscene, I came across a
> question with how to deal with double quotes that are part of "normal"
> string content. Suppose you have MFString, with a single value
>   Some "quotes"
> Question is: should this be encoded in XML as
>   field='"Some "quotes""'
> or should we precede "real" double quotes with backslashes, like
>   field='"Some \"quotes\""'

Once the XML processor is done with it, """ and '"' will be the
same thing.  That is,

        '"Some "quotes""' -> '"Some "quotes""'


        '"Some \"quotes\""' -> '"Some \"quotes\""'

After XML processing, the string is parsed to pick out the MFString
components; '"' is used as the delimiter for these (and thus literal '"'
characters must be escaped).

> The 2nd form looks ugly (what, I have to use both XML entities and
> backslashes?). But it's also more precise: XML DOM reading units may
> assume that " inside attribute is exactly equal to ", and XML
> readers may assume the same. For example, XML reading unit I currently
> use replaces " (and other entities) with real characters, so for
> the 1st form my program sees value
>   "Some "quotes""
> So it's ambiguous which double quotes delimit strings inside MFString,
> and which are "real" double quotes inside content. 2nd form, with
> backslashes, doesn't have this problem.
> Looks like X3D XML spec isn't sure about this itself:
> - Latest version,
> http://www.web3d.org/x3d/specifications/ISO-IEC-19776-1.2-X3DEncodings-XML/Part01/EncodingOfFields.html#SFString
> , shows example with
>   <Text string='"He said, \"Immel did it!\""' />
> Suggesting backslashes are needed. But it's just an example.

That looks fine to me.

However, the spec prose that precedes that example is wrong when it
calls the "string" field an SFString: it's actually an MFString.

> No text in
> SFString/MFString spec says explicitly to use backslashes.
> - Older X3D XML spec shows the same example without backslahes:
> http://www.web3d.org/x3d/specifications/OLD/ISO-IEC-19776-1-X3DEncodings-XML/Part01/EncodingOfFields.html#SFString
> ,
>   <Text string='"He said, "Immel did it!""' />

It looks like the example got corrected, but not the prose. :-/

> If backslashes should indeed be used for double quotes in MFString,
> there remain two questions:
> - Should they be used for SFString too? This means reading SFString from
> X3D XML isn't so trivial (you cannot just take attribute value). But
> would be consistent.

It's not necessary to escape them for SFString because there's no
post-XML processing to break the SFString into components.  (Escaping
them should be harmless, though.)

> - What about other values? For example, META content may contain double
> quotes. Should they be preceded with backslashes also?

AFAIK, MFString is the only field type where this post-XML processing of
the string value occurs.  So, I think that's the only spot.

Braden McDaniel <braden at endoframe.com>

More information about the X3D-Public mailing list