Friday 7 November 2014

What an XML document contains


A well structured XML document contains five kinds of elements
        Root node
        Element Nodes
        Text nodes
        Comments
        Attributes

<?xml version="1.0"?>
<!-- Represents Books information in store -->
<books>
  <book id="1">
    <name>Let Us C</name>
    <author>Yashwant Kanetkar</author>
    <price>245.00</price>   
  </book>
  <book id="2">
    <name>Let Us C++</name>
    <author>Yashwant Kanetkar</author>
    <price>252.00</price>   
  </book>
  <book id="3">
    <name>Java The Complete Reference</name>
    <author>Herbert Schildt</author>
    <price>489.00</price>   
  </book>
  <book id="4">
    <name>HTML5 Black Book</name>
    <author>Kogent Learning Solutions</author>
    <price>485.00</price>   
  </book>  
</books>

Root Node
Root node is the top node in XML hierarchy. It contains entire XML document. In the above example '<books>' is the root node.

Element nodes 


It is the fundamental unit of XML document. The Element node represents an element in an XML document. Elements may contain attributes, other elements, or text. In the above example <book>, <name>, <author>, <price> represents element nodes.

An element can/can't contain text. For Example
 <name></name> is empty element. It contains no text in between tags. Above empty element can also be represented like <name />.
An element can contain mixed data I.e, text and other elements.

Text Nodes
The data between two tags. In the above example 'Let Us C', 'Yashwant Kanetkar', '245.00' are text nodes.

Comments
Comments makes the document more readable. In the above example '<!-- Represents Books information in store -->'  represents comment.

Attributes
XML attributes are used to describe XML elements, or to provide additional information about elements. In the above example 'id' represent unique number given to each book.
 



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment