Thoughts on XML - possible extra shorthand for closing tags

1    06 May 2018 14:08 by u/SithEmpire

I have been poking around on the Internet, and have not found any mention of something which should be an obvious idea. As a big fan of XML, I was thinking about one of its main disadvantages of imposing unnecessary extra bytes to markup the elements, and how it could be improved.

While shorthand already exists for closing an empty element, it seems to me that any closing tag in general pairs unambiguously with the presently-open element regardless of the opening tag name, therefore it should not matter to an XML parser whether the closing tag name actually matches, nor indeed whether any such name need be repeated at all. In practice it would be a good idea to require a match if a name is supplied since the continuity self-test can be useful and increase readability, but I would be all for allowing empty closing tags to work implicitly.

Existing long-form XML:

<element>
    <content>Hello world</content>
    <empty></empty>
</element>

Existing shorthand:

<element>
    <content>Hello world</content>
    <empty/>
</element>

Proposed shorthand extension:

<element>
    <content>Hello world</>
    <empty/>
</>

As best as I can determine, that structure should work. Since element names cannot be the empty string, the </> notation can only be to close the present open/top element, which should be a valid exercise in DRY.

Is this:

  • A bad idea - in which case, why?
  • A good idea - in which case, should I propose it somehow, or just start implementing it in my own parsers for my own XML-based config files?

7 comments

0

Why not just move to json or yaml? Xml is just a pita.

0

I'm okay with JSON, though this was only about a possible enhancement to XML.

0
<cap>what<red>the</>hell</>

is hell red or capitalized?

0

Capitalized - by the spec, tags cannot overlap.

0

While I don't think it is necessarily a bad idea, it won't ever happen as it is not backwards compatible. All parsers currently in use would choke on it and refuse to process as the file would be invalid.

0

It'd work. You should be able to get a working model of this using llvm.

-1

http://imghst.co/94/jsduN8rrF7.jpg

I imagine that right now, you're feeling a bit like Alice. Hmm? Tumbling down the rabbit hole?