Document Element

Each XML document must have one—and only one—document element, which is sometimes referred to as the root element.

Caution

Be careful if you use or read the term root without any further clarification. The XML 1.0 specification uses the term apparently as a synonym for the document entity (Chapter 2 of the XML 1.0 Recommendation) and also as a synonym for the document element (Chapter 2.1).



Elements Nested Inside the Document Element

Typically, nested within the document element is a hierarchy of other elements, represented as start tag/end tag pairs or as empty element tags.

Elements must be nested correctly. The following code shows a correctly nested pair of elements:

<chapter> 
 <section number="1">Some content 
 </section> 
</chapter> 

The start tag of the section element follows the start tag of the chapter element, so the end tag of the section element must come before the end tag of the chapter element.

When correctly nested as shown in the preceding code, the chapter element is termed the parent element of the section element. The section element is termed the child element of the chapter element. An element may have zero, one, or more child elements. An element may have zero or one parent elements. All elements except the document element have one parent element. The document element does not have a parent element.

The following is not legal XML because the elements are not nested correctly:

<chapter> 
<section number="1">Some content 
</chapter> 
</section> 

Attributes

An element may be qualified by adding attribute name/value pairs to its start tag. An attribute is indicated by an XML name, followed by the equal sign and a pair of either quotation marks or apostrophes. The value of the attribute is contained within those quotation marks or apostrophes.

So, if you want to indicate that this is the first edition of this book and that it is published in English, you could add edition and language attributes to the start tag of the book element:

<book edition="1" language='English'> 
<title>Sams Teach Yourself XML in 10 Minutes</title> 
<author>Andrew Watt</author> 
<publisher>Sams Publishing</publisher> 
</book> 

The value of the edition attribute is contained in a pair of quotation marks. The value of the language attribute is contained in a pair of apostrophes.

It is an error to mix double quotes and single quotes as the delimiters of an attribute. In the following code, both the edition and language attributes would generate an error from the XML processor because the attribute value delimiters are not correctly paired.

						<book edition="1' language='English" > 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset