Java Reference
In-Depth Information
The indentation shown in the examples so far has been included just to provide you with visual cues to the
structure of the data. It is not required, and an XML processor ignores the whitespace between elements.
When you are creating XML in an editor, you can use whitespace between elements to make it easier for
a human reader to understand the document. Whitespace can consist of spaces, tabs, carriage returns, and
linefeed characters. You can see that a circle expressed without whitespace, as shown below, is significantly
less readable:
<circle><position><x-coordinate>40</x-coordinate><y-coordinate>50
</y-coordinate></position>30</circle>
Having said that, you don't have complete freedom in deciding where you put whitespace within a tag.
The tag name must immediately follow the opening < or </ in a tag, and there can be no space within an
opening </ delimiter, or a closing /> delimiter in the case of an empty element. You must also separate an
attribute from the tag name or from another attribute with at least one space. Beyond that you can put addi-
tional spaces within a tag wherever you like.
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 in Figure 22-1 .
FIGURE 22-1
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> ele-
ment. The items that appear within the tree structure — the elements and the data items — are referred to as
nodes .
Figure 22-2 shows the structure of the first circle definition in XML that you saw in the previous section.
Even though there's an extra level of elements in this diagram, there are strong similarities to the structure
shown in Figure 22-1 .
FIGURE 22-2
 
 
 
 
Search WWH ::




Custom Search