4 ms·
Children and attributes are different. Attributes are like fields to a record. Parent/child is a relation between records. There are clear criteria for choosin
by Mikhail_Edoshin 3y ago
Children and attributes are different. Attributes are like fields to a record. Parent/child is a relation between records.
There are clear criteria for choosing attribute vs text representation. Text is for humans; all the rest is for the computer. If we see something like this:
<ssn>123</ssn>
this means the text is precious and we cannot alter it, only attach some records (‘ssn’) to some character ranges. And in most cases these records need more fields, so we add attrbiutes:
... <date date="2001-01-01">the first day of that year</date> ...
This is the usual case in markup: we need the computer to do something with the text and use the records as a guide.
But a notational case is different. With notational case we still need the computer to do something, but not about a particular piece of text. (This is actually the general case while text-handling is a specific one.) In this case we can command it directly:
<foo>
<bar id="a" />
<baz ref="a" />
</foo>
There is no text in these records, but we still use notational tools: 1) node type, 2) composition, 3) ordering, 4) naming/referencing. In this case we put everything into attributes.
We can have a notational piece with markup parts or a markup part with notational parts, but each has a clear purpose. There is also a third specific case: we want to switch to another notation and in this case we write it as text inside an XML element.
SVG is a good example. All data go into attributes, text inside elements appears only when 1) it is a part of the drawing, or 2) we are switching to another notation:
<!-- notational -->
<svg ...>
<!-- switching to CSS, still notational -->
<style>
...
</style>
<!-- markup -->
<text>... <tspan class="...">...</tspan> ...</text>
<!-- notational again -->
<rect ... />
</svg>
- madsbuch 3y agothat's a long explanation on how to use various features of a notation. would it be easier to just use json? You have many moving pieces with a complex notation, a complex domain, and potentially multiple architects..
- jerf 3y agoIf you have a simple use case, yes. If you need the things that XML has, no, JSON is not simpler. It is more complex. Every attempt to embed XML/HTML into JSON has resulted in something worse than XML/HTML... and they are all different, too, which is bad. The main problem with XML is that most people don't need what it has. The main problem with XML in the late 1990s and early 2000s is that it was jammed in many places that did not need what it had, and put a bad taste in developer's mouth as a result. It's actually a good solution for its niche, and that niche is large enough it isn't going anywhere, but it is also still only a niche. In that niche you're crazy to try to jam JSON in; out of that niche you're crazy to use XML. The mythos that XML is useless persists because the latter category is a much larger one.
- madsbuch 3y agoIt indeed seems like we agree :)