The fundamental issue with XML is its impedance mismatch with common data structures which forces using Object to XML mappers (whether explicitly or implicitly). It's more or less solved with XML Schemas or DTDs, but if you're looking at just XML, you can't tell whether some element is an array or a single node. Thus JSON is better suited for serialization.
That is really not what attributes are for. I feel a bit of a fraud posting that because I'm not an XML expert and so not really clear what they actually are for. (This reenforces the parent's point: you need to be an expert to know what such a fundamental feature is for.) I remember it's something like "something used to help interpret the actual value" e.g. units of measurement. But most of the time, even if it's non-repeating with no children, you're supposed to use elements rather than attributes.
One problem here is that attributes are so much more compact (and so often easier to read) than elements that it's tempting to use them in places where you ought to use an element (and many people over time have given in to that temptation). Another problem is that the distinction between attributes and elements is almost never useful. That was the parent comment's point by the looks of things.
> The fundamental issue with XML is its impedance mismatch with common data structures
That's probably part of it, but I think at least as problematic is that it has many features that most of the time you don't need and don't want to have to care about. Things like CDATA (also mentioned by the parent comment), custom entities, external entities, DTDs (which can be inline in XML files so you need to know all about DTDs to understand XML properly). That's why there are all sorts of weird XML vulnerabilities that JSON doesn't have. Did you know you can make an XML file that reads your /etc/passwd file when it's parsed? That is not an issue with JSON.
Confusion arise once a human observer is lost.
I had been thinking that all of these extra features that XML have are just a case of massive overengineering that no one would ever need. In fact it's a case of taking something fundamentally meant for text documents with extra markup, as the name implies, and misapplying it to config files and IPC messages which are just not the original domain at all.
I think we should draw on XML strength points. People read articles in browser, not plain text. "Add to cart" is just a POST request with id
curl -d id=foo
yet we have forms and interactivity. Like in literate programming text and data live together, interactive application like a Smalltalk image.In XML we can separate data from presentation.
<?xml-stylesheet type="text/css" href="foo.css"?>
<?xml-stylesheet type="text/xsl" href="bar.xsl"?>
<root>...
Machine receives data, human receives application with documentation, builder. That's exactly what we have today except UI can be plugged to any stored document. To good to be true.I think XML was killed by poor usability. Plain text XML, XHTML and XSLT authoring is not fun.
I am trying to uncover it from DOM perspective [1], so far I like it more than Markdown. XHTML and HTML is just a serialization format. HTML is not a good one [2], [3], [4]. XSLT may have nice GUI or compact syntax like RELAX NG.
[1] http://sergeykish.com/live-pages
[2] http://sergeykish.com/script-style-is-cdata-in-html
[3] http://sergeykish.com/pre-newline-ignored-in-html-test
[4] http://sergeykish.com/content-after-html-appended-to-body-in...
Not only can SGML (but not XML on its own) read /etc/passwd, it can format it into fully-tagged markup and then render it into eg an HTML table. Demonstrating what SGML/XML is actually designed for: encoding and authoring semistructured text. This can't be overstated in discussions like these where use cases for config formats, service payload formats, and actual text authoring are all thrown into the same basket when they shouldn't.
Btw: you can parse and canonicalize this new config file format into markup using the same SGML mechanism you'd be using for CSVs like /etc/passwd, namely short references
Btw2: you can skip/ignore markup declarations in XML, including whole declaration sets (DTDs) since these can be recognized using plain greedy regexpes, though you can't ignore entity declarations when actually used in your XML body text
No you don't... the parent commenter explained to you what it's for in a simple and concise manner... you chose to not accept that even though you're not an expert in this, and then complains you need to be an expert to do it?!?
(The true difference is explained in sibling comments to yours, by sergeykish and tannhaeuser, if you're interested.)
I don’t doubt they meant to be clear, but reading it they were not and raised more questions than were answered.
As an example:
Wouldnt attributes be better served as details about the current element?
Wouldn’t elements be better served as “I am a child of the parent”?
Why would I use an attribute as a “non-repeating child” when semantically that doesn’t make sense when looking at the document? The attribute is inside the element’s definition, and seems to me attributes should be used to further describe the element being presented itself, and not be structural or describe itself as a child in any way.
In a minute I can read and write json from most languages I use.
In the same amount of time, I'm still wondering if I should use a tag or attribute in xml. cdata? expat?
It's not that xml isn't a good technology. It's that it's not appropriate for general use, especially in comparison to simpler alternatives.