Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Compared to other serialization languages, one of the main criticisms directed at XML is its verbosity; JSON's more terse and readable for most cases, but not all.

But it seems to me that we could cut a lot of the excess from XML simply by stripping away the names from the closing tags. With proper indentation readability shouldn't be an issue (it should be an improvement, if you ask me), and since they're not structurally required any decent XML editor/viewer could easily be made to strip/hide or add them. As such, the two formats should be completely equivalent and interchangeable.

Compare the following (source taken from http://www.w3schools.com/xml/simple.xml):

<breakfast_menu>
    <food>
        <name>Belgian Waffles</name>
        <price>$5.95</price>
        <description>
                    Two of our famous Belgian Waffles with plenty of real maple syrup
        </description>
        <calories>650</calories>
    </food>
    <food>
        <name>Strawberry Belgian Waffles</name>
        <price>$7.95</price>
        <description>
                    Light Belgian waffles covered with strawberries and whipped cream
        </description>
        <calories>900</calories>
    </food>
    <food>
        <name>Berry-Berry Belgian Waffles</name>
        <price>$8.95</price>
        <description>
                    Light Belgian waffles covered with an assortment of fresh berries and whipped cream
        </description>
        <calories>900</calories>
    </food>
    <food>
        <name>French Toast</name>
        <price>$4.50</price>
        <description>
                    Thick slices made from our homemade sourdough bread
        </description>
        <calories>600</calories>
    </food>
    <food>
        <name>Homestyle Breakfast</name>
        <price>$6.95</price>
        <description>
                    Two eggs, bacon or sausage, toast, and our ever-popular hash browns
        </description>
        <calories>950</calories>
    </food>
</breakfast_menu>

and

<breakfast_menu>
    <food>
        <name>Belgian Waffles</>
        <price>$5.95</>
        <description>
                        Two of our famous Belgian Waffles with plenty of real maple syrup
        </>
        <calories>650</>
    </>
    <food>
        <name>Strawberry Belgian Waffles</>
        <price>$7.95</>
        <description>
                        Light Belgian waffles covered with strawberries and whipped cream
        </>
        <calories>900</>
    </>
    <food>
        <name>Berry-Berry Belgian Waffles</>
        <price>$8.95</>
        <description>
                        Light Belgian waffles covered with an assortment of fresh berries and whipped cream
        </>
        <calories>900</>
    </>
    <food>
        <name>French Toast</>
        <price>$4.50</>
        <description>
                        Thick slices made from our homemade sourdough bread
        </>
        <calories>600</>
    </>
    <food>
        <name>Homestyle Breakfast</>
        <price>$6.95</>
        <description>
                        Two eggs, bacon or sausage, toast, and our ever-popular hash browns
        </>
        <calories>950</>
    </>
</>
share|improve this question
5  
Are you talking about HTML or XML? Those are two very different languages! –  Jörg W Mittag Jul 17 '13 at 10:19
2  
Closing tags are optional in HTML but not in XML, so that's one difference that is directly relevant to your question. –  Jörg W Mittag Jul 17 '13 at 10:30
1  
@JörgWMittag - No. Closing tags are not optional in all HTML tags. w3.org/TR/html401/index/elements.html –  Rob Jul 17 '13 at 10:35
1  
1  
@Rob: Yes, sorry, I should've been more clear. The OP was specifically asking about having to repeat the element name in the closing tag, and that's not necessary in HTML. HTML supports Null End Tags, so you can always replace, say, <em>Some emphasized text</em> with <em/Some emphasized text/. –  Jörg W Mittag Jul 17 '13 at 10:44

2 Answers 2

Can we change XML format (i.e. create a new language which doesn't have the verbosity issue)? Yes, we can.

In order to completely migrate to the "better XML" (let's call it BETXML), it would require to:

  • Reimplement all the parsers,

  • Rewrite all applications which currently use XML,

  • Rewrite all protocols based on XML.

Or we can keep everything in place, and just invent a new language and wait until it starts to be adapted everywhere. The only issue is that benefits of a new language are very limited. Applications which require less verbose language already use JSON. How would you convince people that BETXML is superior to XML and JSON?

share|improve this answer

I fail to see the big gain with the </> variant. Are you talking about readability for the human eye? In that case I would take ordinary XML any day rather than trying to figure out what the code is trying to tell me when I see something like this in the middle of a file:

    ...
    </></></></></></></>
    <something>
    ...

An XML file is a data container. Just because you can read and edit it by hand in a text editor does not necessarily mean that it is a good idea to do so. It is primarily meant to convey data from one application to another (or, yes, to just store data).

So maybe you mean the actual file size? Well, if that is so important, then you are probably not using the most suitable file format anyway.

But a more important reason for keeping XML as it is, is that when there is a structural error in a real XML file, the tag/end-tag design of XML makes it very easy for a parser to determine where the problem lies, and thereby to determine if the rest of the file can still be used.

If there is an end tag missing in your </> variant, it is much more difficult for the parser find the cause of the problem. And if you do not have a good DTD, then the parser will not even see that anything is wrong until it reaches the end of the file and (hopefully) detects that there is a level imbalance. And at that point there is nothing to do but to reject the whole file since there is no way of telling where the error is.

share|improve this answer
3  
A missing </> is really no different than a missing 'end' or } in any other language that most of us deal with day in and out. –  Rig Jul 17 '13 at 16:35
2  
@Rig, you would be right if this was a program (I've been programming computers for 34 years), but it is not.This is a data structure, more likely to have been generated by a (well or badly written) program somewhere than written by a human, meaning that the contents of the file is more likely packed (no white-space) rather than nicely structured for the human eye. –  Boise Jul 18 '13 at 12:59
    
Does that not mean we need to raise the bar higher on those programs? ;) –  Rig Jul 18 '13 at 16:19
3  
Hehe, no I don't think so :-) I code a lot in Pascal/D80, a language for embedded real-time programs. One of the modifications that it introduces to the old standard Pascal is that, rather than using a simple "end" to close all types of blocks, it uses do .. enddo, if .. endif, and so on. That is, much like the point of the named end tags in XML. –  Boise Jul 18 '13 at 21:04
    
@Rig: in programming languages, I can control the nesting level by extracting methods and classes. –  kevin cline Jul 18 '13 at 23:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.