28 ms·
One reason to dislike XML is that it can't actually encode text. This is deliberate, key people involved in XML standardization really hate some of the charact
by tialaramex 6y ago
One reason to dislike XML is that it can't actually encode text.
This is deliberate, key people involved in XML standardization really hate some of the characters (particularly some "control characters") in text, they don't think those characters should exist, so, they outlawed them in XML.
I know what you're thinking, "Just escape them". Nope. I didn't say you have to escape them, I said they're outlawed, the XML definition says these characters, whether escaped or otherwise, must not appear in an XML document and some XML libraries enforce this requirement from the standard.
Now of course if you know this will happen and you want to sidestep it you can encode all your text in some other way (e.g. as Base64) and then use XML, but wait a minute, the whole point of XML is that it's a text encoding, for encoding text, so this is crazy.
In systems I've built that are mandated to emit XML and yet are expected to handle text anyway, I patiently explain the problem and unless people seem stirred awake and back off on requiring XML, I then convert all prohibited characters to U+FFFD - the Unicode replacement character - and they can keep both halves of the resulting broken garbage.
- saurik 6y agoA "control character" (such as form feed) is kind of by definition not "text", but more importantly this was fixed for XML 1.1, which is like 14 years old at this point.
- matharmin 6y agoI have never seen XML 1.1 used in practice. How many parsers actually support it?
- GoblinSlayer 6y agoInteroperability is exactly the reason why control characters weren't added to xml 1.0. And >You are encouraged to create or generate XML 1.0 documents if you do not need the new features in XML 1.1; XML Parsers are expected to understand both XML 1.0 and XML 1.1.
- ebruchez 6y agoXML 1.1 was considered a failure by W3C and it is not recommended that anybody use it.
- sk5t 6y agoPrecisely which (printable?) characters do you understand to be outlawed in cdata/pcdata by what XML standard? For what it's worth, I'd not take a charitable view of this bold assertion in the general case.
- mrbonner 6y agoYou heard of CDATA, bro?
- ithkuil 6y agoStandard says: " CData ::= (Char* - (Char* ']]>' Char)) Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] / any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */ " Which means the following characters are illegal: #x0, #x1, #x2, #x4, #x5, #x6, #x8, #xB #xE, #x18, #x19, #x1A, and #x1C I'm not arguing here for or against inclusion of these characters as legal characters in a text block; just saying that GP's point is oblivious to actual encoding (explicit escapes or cdata)
- archgoon 6y agoThis is an odd criticism. JSON, the popular alternative, also has this 'issue'. In fact, almost any non binary solution, like protobufs, will have this issue, as it's a text, not byte, encoding. The reason for outlawing these characters is that they aren't text, they are, as the name implies, control characters.
- tialaramex 6y agoUnlike XML you can simply escape control characters in JSON and "almost any non binary solution". Prohibiting this is a weird misfeature of XML.
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- throwaway_pdp09 6y agoOf course it can't. It's designed to be human-readable which control characters aren't. What eg. does BEL (ascii 07 IIRC) look like do you reckon.
- bawolff 6y agoIdeally it would look like  Its useful to be able to encode arbitrary characters even if they aren't human readable.
- kzrdude 6y agoFair. Is the NUL character included in that?
- throwaway_pdp09 6y agohttps://en.wikipedia.org/wiki/Valid_characters_in_XML https://en.wikipedia.org/wiki/Valid_characters_in_XML "Note that the code point U+0000, assigned to the null control character, is the only character encoded in Unicode and ISO/IEC 10646 that is always invalid in any XML 1.0 and 1.1 document" That wiki article may be worth a skim.
- kzrdude 6y agoI'm asking the commenter's opinion, not about current state of XML. Still thanks for the link.