next up previous contents
Next: Identifying XML Data by Up: Representing Fieldbus Data and Previous: Representing Fieldbus Data and   Contents

XML Attributes and XML Elements

Data may be stored in XML documents in various ways. Often the document designer has to decide if data should be embedded in XML elements or XML attributes. The SOAP message in listing 20 shows an example where the same data is modeled in XML elements (line 2 to 6) or in XML attributes (line 8)74.

language=XML
\begin{lstlisting}[caption={Storing Data in XML Elements or XML Attributes}
,la...
...d=''Sensor1'' value=''12.2'' quality=''good''/>
</s:Body>
\par
\end{lstlisting}

The decision between these two models is not easy and it is a topic which is often discussed. [BIR01] suggests: ``Use an element to represent objects that can exist on their own independent of any container element that they may be child of, and attributes to represent its properties, which cannot exist without the object.'' Generally, the following points should be taken into account:

Hierarchies:
Data structures which contain hierarchies can only be stored in XML elements as XML attributes cannot contain subelements.
Multiple Values:
XML Attributes may only occur once, XML code such as <server node="1" node="2"/> is not well-formed and is rejected by XML parsers.
Metadata:
Data with related metadata can only be modeled by elements, such as <element metadata="123">data</element>.
Readability and Document Size:
The usage of XML Attributes leads to smaller documents, as can be seen in Listing 20. Moreover, the XML parser75 is faster in dealing with XML attributes. On the other hand, human legibility of XML documents is often better when data is stored in XML elements.
Order of Data:
If the order of data is an issue, it has to be modeled by elements as the order of XML attributes cannot be specified by XML Schema or DTD.
Extensibility:
Generally, elements are easier to extend than attributes. Elements may contain subelements, which is not possible for attributes.

Applied to fieldbus data, the decision between XML attributes and XML elements is also not easy. Standards in chapter 3 show that some fieldbus data may be encapsulated in both ways. However, human legibility and extensibility may be favored over document size and processing speed76, so that XML elements may be the preferred way to represent fieldbus data in most cases. Some data such as the value will also need metadata which makes the usage of XML elements mandatory.


next up previous contents
Next: Identifying XML Data by Up: Representing Fieldbus Data and Previous: Representing Fieldbus Data and   Contents
Hermann Himmelbauer 2006-09-27