XML Document Structure

The following figure gives you an overview of an XML document. An XML document contains XML nodes of different types. Nodes of type "Element" can have child nodes and therefore complex structures can be defined in an XML document.

Raw XML Content Type of Node Value Number of Children
<?xml version="1.0" ?> Processing Instruction
<Order> Element 3
<!-- This is an order > Comment This is an order
<Name> Element 1
Scott Bradley Text Scott Bradley
</Name>
<OrderItems> Element 1
<Item id="1"> Element with Attribute 1
Lord of the Rings Text Lord of the Rings
</Item>
</OrderItems>
</Order>

The left column shows you the raw XML content. The second column shows you the type of a node. As you can see, there are different types of nodes in an XML document. The third column shows you the value of a node and the fourth column displays the number of children a specific node has.

Each element in an XML document is called a node - where there are different types of nodes. Element nodes are those nodes that are defined as follows: "<{Name of node}>". Element nodes need a closing node tag ("</ {Name of node}>") if the node has child nodes - otherwise it would be possible to define an element node that has no child nodes as the following: "<{Name of node} />", e.g.: "<Order />"

Element nodes can have multiple attributes which are defined in the starting tag of a node - you can see in the example above that the node named "Item" has an attribute called "id" with the value "1".

Element nodes can have a text value - you can see in the example above that the node named "Name" has the text value "Scott Bradley". Although it seems that the value belongs to the node name, the text value itself is a separate node of type text and is a child of "Name".

The example above shows us two more node types of common use: <?: marks a process instruction: these are nodes telling the XML parser specific things about the XML document. <!--:marks a comment node: this type of node allows you to define comments.