[x3d-public] Newlines inside a string in VRML and X3D

Michalis Kamburelis michalis.kambi at gmail.com
Wed May 10 17:33:45 PDT 2017


During the today's talk at Web3d teleconference, there was an
uncertainty how to specify newlines inside VRML or X3D string
(MFString or SFString).

Here's my knowledge:

1. In VRML / classic encoding, you just use the fact that newlines are
"nothing special" inside a string literal. The string is parsed up to
the matching double-quote. So just use this:

  Text {
    string "One line
  Another line
  Yet another line" }

  "Newline" is used here in a broad sense: character #10, character
#13, or any combination of them. (#13 + #10 characters on Windows, #10
on Unix, #13 on classic Mac OS <= 9.) Proper applications should apply
the same logic to detect any newline on any OS, so that a file created
on Unix is rendered the same on Unix and on Windows, and vice versa.
That's a normal issue that you need to deal with in a cross-platform

2. In XML encoding, the XML specification has it's idea about how to
encode newlines in XML attribute values.

  You use character entities like 
 to encode them. So,
encode your newlines as 
 (if you like Unix) or 
 (if you
like Windows). I say "like", because it's really your personal
preference, a proper cross-platform application will treat them both
equivalently, regardless of the actual operating system it is being
executed on.

  So, this is correct:

  <Text string='"One line
Another line
Yet another line"' />


  <Text string='"One line
Another line
Yet another line"' />

  Warning: Do *not* use a literal newline character in XML attribute,
as that will be "normalized" into a space character.

  IOW, THIS IS INCORRECT (a newlines below are "seen" as an ordinary
space character by an application):

  <Text string='"One line
  Another line
  Yet another line"' />

  See the XML specification
https://www.w3.org/TR/REC-xml/#AVNormalize, "3.3.3 Attribute-Value
Normalization" says: "For a white space character (#x20, #xD, #xA,
#x9), append a space character (#x20) to the normalized value." .

This is what I know:) This matches at least my implementation
(view3dscene and Castle Game Engine). A simple example is in

Testing this with other browsers is welcome. But it's not trivial, as
newlines are ignored e.g. for Text.string rendering. I think you need
to use a shader code or Script code to somehow "uncover" whether the
newlines are really newlines inside the content.

Anyway, at least point AD 2 is not related to X3D, it's defined 100%
by the XML specification, so I don't expect any incompatibilities here
between implementations.

Best regards,

More information about the x3d-public mailing list