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

Joe D Williams joedwil at earthlink.net
Fri May 19 22:26:32 PDT 2017


Usually, the way you get a new line in VRML and X3D is by a new SSF in 
the string node.
For example

<text string='"one line" "next line"' />

there is always a 'newline' between each quoted string.

Thanks and Best,
Joe

----- Original Message ----- 
From: "Michalis Kamburelis" <michalis.kambi at gmail.com>
To: "X3D Graphics public mailing list" <x3d-public at web3d.org>
Sent: Wednesday, May 10, 2017 5:33 PM
Subject: [x3d-public] Newlines inside a string in VRML and X3D


> Hi,
>
> 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
> application.
>
> 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"' />
>  -------------
>
>  or
>
>  -------------
>  <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
> https://github.com/michaliskambi/x3d-tests/tree/master/newlines_in_string
>
> 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,
> Michalis
>
> _______________________________________________
> x3d-public mailing list
> x3d-public at web3d.org
> http://web3d.org/mailman/listinfo/x3d-public_web3d.org 




More information about the x3d-public mailing list