Skip to main content
IBM  
Shop Support Downloads
IBM Home Products Consulting Industries News About IBM
IBM developerWorks : XML : Education - Tutorials
Introduction to XML
ZIPPDF (letter)PDF (A4)e-mail
Main menuSection menuFeedbackPreviousNext
3. XML document rules
  


The root element page 3 of 10


An XML document must be contained in a single element. That single element is called the root element, and it contains all the text and any other elements in the document. In the following example, the XML document is contained in a single element, the <greeting> element. Notice that the document has a comment that's outside the root element; that's perfectly legal.


<?xml version="1.0"?>
<!-- A well-formed document -->
<greeting>
  Hello, World!
</greeting>
          

Here's a document that doesn't contain a single root element:


<?xml version="1.0"?>
<!-- An invalid document -->
<greeting>
  Hello, World!
</greeting>
<greeting>
  Hola, el Mundo!
</greeting>
          

An XML parser is required to reject this document, regardless of the information it might contain.


Main menuSection menuFeedbackPreviousNext
Privacy Legal Contact