Root element

From Wikipedia, the free encyclopedia
Jump to: navigation, search

Each XML document has exactly one single root element. It encloses all the other elements and is therefore the sole parent element to all the other element.So ROOT element is also called as PARENT element.

The World Wide Web Consortium defines not only the specifications for XML itself,[1] but also the DOM, which is a platform- and language-independent standard object model for representing XML documents. DOM Level 1 defines, for every XML document, an object representation of the document itself and an attribute or property on the document called documentElement. This property provides access to an object of type element which directly represents the root element of the document.[2]

 <parent>
   <child>content</child>
   <child attribute="att"/>
 </parent>

There can be other XML nodes outside of the root element.[3] In particular, the root element may be preceded by a prolog, which itself may consist of an XML declaration, optional comments, processing instructions and whitespace, followed by an optional DOCTYPE declaration and more optional comments, processing instructions and whitespace. After the root element there may be further optional comments, processing instructions and whitespace within the document.[4]

Within the root element, apart from any number of attributes and other elements, there may also be more optional text, comments, processing instructions and whitespace.

A more expanded example of an XML document follows, demonstrating some of these extra nodes along with a single rootElement element.

  1.  <?xml version="1.0" encoding="UTF-8"?>
    
  2.  <!DOCTYPE example [<!ENTITY copy "&#xA9;">]>
    
  3.  
    
  4.  <rootElement attribute="xyz">
    
  5.    <contentElement/>
    
  6.  </rootElement>
    
  7.  
    
  8.  <!-- comment nodes may appear almost anywhere -->
    

References[edit]

  1. ^ The current W3C XML 1.0 specification
  2. ^ The 'documentElement' definition in the W3C DOM Level 1 specification
  3. ^ The 'well-formed document' section of the W3C XML specification
  4. ^ The 'prolog' section of the W3C XML specification