The Root Element
Home ] Up ] The Document Prolog ] XML Elements ] [ The Root Element ] XML Attributes ] Attribute vs. Element? ] Whitespace and Comments ] XML Character Entities ] CDATA Sections ] Processing Instructions ] Well-Formed Documents ]

 

 

Every XML document must have one, and only one, root element:

<?xml version="1.0" encoding="utf-8"?>
<address>
  <street>31 Concord Rd.</street>
  <city>Lower Farthing</city>
  <state>Old Hampshire</state>
  <zip>99999</zip>
</address>

In this case, the root element is <address>.

The following is incorrect XML, because of the extra <address> element:

<?xml version="1.0" encoding="utf-8"?>
<address>
  <street>31 Concord Rd.</street>
  <city>Lower Farthing</city>
  <state>Old Hampshire</state>
  <zip>99999</zip>
</address>
<address>
  <street>19 Farson St.</street>
  <city>Upper Grommet</city>
  <state>Old Jersey</state>
  <zip>99998</zip>
</address>

Click here to see what happens if you try to display the above XML in your browser.

 
The page was last updated February 19, 2008