▲ | bayindirh 2 days ago | ||||||||||||||||||||||
This is why you can have attributes in a tag. You can make an XML file self explanatory. Consider the following example:
Most parsers have type aware parsing, so that if somebody tucks string to a place where you expect integer, you can get an error or nil or "0" depending on your choice. | |||||||||||||||||||||||
▲ | dminik 2 days ago | parent [-] | ||||||||||||||||||||||
I had the displeasure of parsing XML documents (into Rust) recently. I don't ever want to do this again. JSON for all it's flaws is beautifully simple in comparison. A number is either a number or the document is invalid. Arrays are just arrays and objects are just objects. XML on the other hand is the wild west. This particular XML beast had some difficulty sticking to one thing. Take for instance lists. The same document had two different ways to do them:
Various values were scattered between attributes and child elements with no rhyme or reason.To prevent code reuse, some element names were namespaced, so you might have <ThingName /> and <FooName />. To round off my already awful day, some numbers were formatted with thousands separators. Of course, these can change depending on your geographical location. Now, one could say that this is just the fault of the specific XML files I was parsing. And while I would partially agree, the fact that a format makes this possible is a sign of it's quality. Since there's no clear distinction between objects and arrays you have to pick one. Or multiple. Since objects can be represented with both attributes and children you have to pick one. Or both. Since there are no numbers in XML, you can just write them out any way you want. Multiple ways is of course preferable. | |||||||||||||||||||||||
|