XML data is commonly retrieved by addressing an element by its name (tag) and retrieving its value. However, XML also provides addressing by the order of elements, similar to arrays in conventional programming languages. A developer designing XML documents, may therefore choose between these two addressing schemas. Listing 21 shows an example where fieldbus data is represented by XML code in three ways.
Line 1 to 5 depicts the commonly used addressing schema, where data is encapsulated in XML elements that have unique names. Line 7 to 11 is an alternative where the data is modeled similar to an array. Data can be retrieved by the element's index, similar to an array. It is obvious that the order of the elements is important this way. Line 13 to 17 shows a mixture of the two examples above, where elements contain unique attributes which may be used for addressing.
A quick look at the listing shows the advantages of the named addressing schema:
The above examples make it obvious that the named addressing scheme is the superior method for most fieldbus data. The second example in listing 21 is hard to address and to constrain by XML Schema, and it is meaningless to human readers. The third example has no advantages compared to the first but contains redundant information while adding unneeded complexity to the XML code.
One exception are arrays which are embedded in XML documents. Listing 22 shows a possible method for embedding historic fieldbus data in an XML document.