Closing tag in XML

by

I always wondered why they didn’t allow an optional closing tag of “</>” that would close the corresponding open tag.

For example:

<p>This is a string with something <b>bold</> in it.</p>

where “</>” is closing the <b> tag. Or:

<blah><bleh><blih><bloh>bluh</></></></>

which is shorter than:

<blah><bleh><blih><bloh>bluh</bloh></blih></bleh></blah>

I fell it is a shortcut like the stand-alone tag <tag/>.


6 responses to “Closing tag in XML”

  1. DBLaci Avatar

    Yeah, you’re right, i wondered about this too. I can’t imagine where would this lead to problem.

  2. DBLaci Avatar

    And let me mention that your example is wrong :)

    bluh

    is invalid, it should be
    bluh

    :)

  3. Rose Avatar

    It would work, but it would be awful to debug a nesting issue. For example:

    To what element does this text belong?

    If you make sure the XML has proper indentation, the nesting issue isn’t a problem (below is the same code with proper indentation. Yet because indentation is insignificant, we need another mechanism to keep the XML human-readable. In this example, human-readable means a human can easily see which content belongs to which element. The solution is to name which element each closing tag refers to.

    To what element does this text belong?

    When we give the closing tags names, even it’s clear to see even in improperly indented XML that the text belongs to element .

    To what element does this text belong?

    See more answers to this question at http://stackoverflow.com/questions/6785332/are-xml-html-tag-names-inside-closing-tags-really-necessary/10777469#10777469

  4. Rose Avatar

    Great question. It would work, but it would be awful to debug a nesting issue. For example:

    To what element does this text belong?
    If you make sure the XML has proper indentation, the nesting issue isn’t a problem (below is the same code with proper indentation. Yet because indentation is insignificant, we need another mechanism to keep the XML human-readable. In this example, human-readable means a human can easily see which content belongs to which element. The solution is to name which element each closing tag refers to.

    To what element does this text belong?

    When we give the closing tags names, even it’s clear to see even in improperly indented XML that the text belongs to element .

    To what element does this text belong?

    See more answers to this question at:

    http://stackoverflow.com/questions/6785332/are-xml-html-tag-names-inside-closing-tags-really-necessary/10777469#10777469

  5. Rose Avatar

    It would work, but it would be awful to debug a nesting issue. For example:

    
    
    To what element does this text belong?
    

    If you make sure the XML has proper indentation, the nesting issue isn’t a problem (below is the same code with proper indentation. Yet because indentation is insignificant, we need another mechanism to keep the XML human-readable. In this example, human-readable means a human can easily see which content belongs to which element. The solution is to name which element each closing tag refers to.

    
    
        
        
        
        
        
            
            
            
                
                
                
                
            
            
            
            To what element does this text belong?
        
    
    
    

    When we give the closing tags names, even it’s clear to see even in improperly indented XML that the text belongs to element

    
    

    .

    
    
    To what element does this text belong?
    

    See more answers to this question at:

    http://stackoverflow.com/questions/6785332/are-xml-html-tag-names-inside-closing-tags-really-necessary/10777469#10777469

    1. Pablo Avatar

      Hello Rose,

      Thanks for your reply. I think badly indented XML could cause confusion with or without closing tags. Most editors would actually help us in any of those cases but I see your point, it does reduce the readability of XML.

      Unfortunately, the commented system of WordPress broke your formatting, but it’s easy to understand from the stackoverflow link you posted.

Leave a Reply

You may also like:

If you want to work with me or hire me? Contact me

You can follow me or connect with me:

Or get new content delivered directly to your inbox.

Join 5,043 other subscribers

I wrote a book:

Stack of copies of How to Hire and Manage Remote Teams

How to Hire and Manage Remote Teams, where I distill all the techniques I've been using to build and manage distributed teams for the past 10 years.

I write about:

announcement blogging book book review book reviews books building Sano Business C# Clojure ClojureScript Common Lisp database Debian Esperanto Git ham radio history idea Java Kubuntu Lisp management Non-Fiction OpenID programming Python Radio Society of Great Britain Rails rant re-frame release Ruby Ruby on Rails Sano science science fiction security self-help Star Trek technology Ubuntu web Windows WordPress

I've been writing for a while:

Mastodon

%d bloggers like this: