XML: Building Blocks and Basic Rules

Nesting Elements

The XML specifications require that within an XML document all elements have to be nested within a so-called root element. If you take the simple example of a dictionary, the root element could be . Nested within the root element you could then have many elements. A very basic structure might look something like this:

1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="UTF-8"?>
<dictionary>
    <entry>
        This is the first entry!
    </entry>
    <entry>
        This is the second entry!
    </entry>
</dictionary>



In this example, all <entry> elements are nested within <dictionary> element which is the root element of this XML document. Furthermore, each address entry can other have elements nested in it. Each entry could then contain other elements:

1
2
3
4
5
6
7
8
<entry>
   <lemma>lexicographer</lemma>
   <grammar>noun</grammar>
   <sense>
      <definition>A harmless drudge.</definition>
      <example>Some lexicographers are mad!</example>
   </sense>
</entry>