Closing tag in XML

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/>.

Advertisements

6 Replies to “Closing tag in XML”

  1. 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

  2. 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

  3. 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. 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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s