The Coordinator
The Coordinator

Reputation: 13137

Xml 1.1 vs 1.0 library use

XML 1.1 versus 1.0

Given that certain characters in 1.0 are no longer accepted in 1.1, which is the correct way to set Text on an xml element?

if Element e = new Element("foo")

Should I do this:

e.setText(sanitized_text_illegal_characters_removed_or_escaped) ?

or

e.setText(any_text)

Upvotes: 0

Views: 307

Answers (1)

parsifal
parsifal

Reputation: 592

You've got it backwards: XML 1.1 relaxed the character limitations. Whereas XML 1.0 does not permit most of the ASCII control characters, XML 1.1 permits all control characters other than NUL (both prohibit surrogates).

If you have to deal with strings that contain prohibited characters, you have two choices: escape them using an application-dependent scheme, or remove them. Note that you can not use an XML character reference (aka numeric entity) to "escape" the values; the parser will translate these references and reject them.

However, before you go to the trouble of doing this, you should verify that you actually have to.

Upvotes: 2

Related Questions