Simple: parse
<foo bar="zot">quux</foo>
as (JSON-like) {
"foo": {
"bar" : "zot",
"" : "quux"
}
}
Problem solved, XML is now logical again.Simple: parse
<foo bar="zot">quux</foo>
as (JSON-like) {
"foo": {
"bar" : "zot",
"" : "quux"
}
}
Problem solved, XML is now logical again. <foo bar="zot">quux</foo>
would be represented as /foo/@bar=zot
/foo=quux
I think data serialization formats of this particular kind are underused. They are dead simple to parse while still being reasonably human-friendly (more so than XML, I'd say). Get rid of the attributes and introduce the convention that nodes with children named "0", "1", ... , "$N" are arrays and you can represent JSON.<foo bar="zot"><baz>quux</baz></foo>
[foo]
@bar="zoot"
[baz]
"quux"
[]
[]
I figured you would save a little in the serialization. In practice I rarely need such a thing, and just serialize a structure to whatever I'm working with (s expressions, or in java xstream etc since those xml files are read somewhere...)That said, the JSON representation has a bug: what if there are multiple child elements? A fix would be using numeric indices for the children rather than the empty string. Then it would look both like an object with keys (attributes) and an array (of elements). Though, if you want to serialize that back into XML, you would need to make sure you never use non-strings as attribute values! Another bug is that the objects don't maintain their tag name; writing code to process data in this representation would be fairly annoying because a pointer to an element would be an object plus a key, rather than just an object. A fix for this would be to have a "tag" key inside the object.