Main Page

Previous Next

Data Structure in XML

The ability to nest elements is fundamental to defining the structure of the data in a document. We can easily represent the structure of the data in our XML fragment defining an address, as shown below.

Click To expand

The structure follows directly from the nesting of the elements. The <address> element contains all of the others directly, so the nested elements are drawn as subsidiary or child elements of the <address> element. The items that appear within the tree structure – the elements and the data items – are referred to as nodes.

The diagram below shows the structure of the first circle definition in XML that we created in the previous section. Even though there's an extra level of elements in this diagram, there are strong similarities to the structure above.

Click To expand

We can see that both structures have a single root element, <address> in the first example and <circle> in the second. We can also see that each element contains either other elements or some data that is a segment of the document content. In both diagrams all the document content lies at the bottom. Nodes at the extremities of a tree are referred to as leaf nodes.

In fact an XML document always has a structure similar to this. Each element in a document can contain other elements, or text, or elements and text, or it can be empty.

Previous Next
JavaScript Editor Java Tutorials Free JavaScript Editor