Russ
Russ

Reputation: 2006

Valid XML or not (encoded characters)?

I have the following xml snippet which gets sent to an external web service (note the line feeds):

<xml>
<address>Bob Jones
100 Main St.
Smallville Ohio 39391</address>
</xml>

The web service responds with:

<xml>
<address>Bob Jones&#10;100 Main St.&#10;Smallville Ohio 39391</address>
</xml>

In essence the service seems to be encoding line feeds with an html encoding? The only xml encoded values I've seen are:

&lt;
&gt;
&quot;
&amp;
&apos;

or have the following format to represent unicode characters (where u is a digit)

&#uuuu;

The only encoding i've found online that uses &#10; seems to be html encoding. Is this also a valid xml encoding? I thought from the format above it would have to have 4 digits. Online xml checkers are telling me it's valid xml which is surprising me. If this is valid xml, is it bad practice to encode a completely valid xml character (line feed) for seemingly no reason?

Upvotes: 0

Views: 99

Answers (1)

bmargulies
bmargulies

Reputation: 100051

&#10; is always valid in XML, and a normal parser will simply replace it with the character. &#ANY_16_bit_number; is in fact also valid. You can specify any Unicode character.

Upvotes: 1

Related Questions