Well Formed XML Documents

Well formed XML documentsAn XML document is “well formed” if it meets the following criteria:

  • The document must have one root element only
  • Every opening XML tag must have a corresponding closing tag.
  • All attribute values must be quoted
  • XML elements must be properly nested.


One root element only

An XML document must have one root element and one root element ONLY.

The following is valid:

<?xml version="1.0" encoding="UTF-8"?>
<library>
</library>

 

The following is NOT valid

<?xml version="1.0" encoding="UTF-8"?>
<library>
</library>
<store>
</store>

 

Matching Tags

Any opening tag must have a corresponding closing tag. This applies to both the long form and the short form of a tag.

The following is valid:

<book>
    <title lang="english">All about dogs</title>
    <author>Someone</author>
    <isin>true</isin>
    <daysuntilreturn>0</daysuntilreturn>
    <price/>
</book>

 

The following is NOT valid:

<book>
    <title lang="english">All about dogs</title>
    <author>Someone
    <isin>true</isin>
    <daysuntilreturn>0</daysuntilreturn>
    <price>15.10</price>
</book>

 

Quoted Attribute Values

All attribute values must be enclosed in double-quotes.

The following is valid:

<category name="dogs">

 

The following is NOT valid:

<category name=dogs>

 

Nested Elements

XML elements must be properly and logically nested.

The following is valid:

<tagA>
    <tagB></tagB>
</tagA>

 

The following is NOT valid:

<tagA>
    <tagB>
</tagA>
    </tagB>

 

Posted in XML and tagged .

Leave a Reply