Datasheet

Displaying Data on the Web
13
For simple information such as this, a text file provides an easy way of reading and writing data. If the
data to be stored has more structure, however, it becomes far more time consuming. For example, it
could be the case that each of these employees has placed an order for some office supplies. Rather than
adding all of that information to the text file as well, it would be better to hold it separately, and then
define relationships between the two sets of data.
When the data starts to gain 'structure' in this manner, a method of giving the file itself some structure
must be found, and a way of retrieving it and representing it in memory must also implemented. One
way of doing this is through the use of XML.
XML
In some ways, XML documents can be thought of as a stepping-stone between text files and databases;
they store data using text files, but use a hierarchical and relational format that is both extensible and
self-describing, providing a number of the benefits of a database system. Before we go any further in
explaining the use of XML as a data source, a sample fragment of an XML document is shown below:
<company>
<employees>
<employee LastName="Smith" FirstName="John"
BirthDate="05-04-1979" Country="UK" />
<employee LastName="Bloggs" FirstName="Joe"
BirthDate ="29-09-1981" Country="US" />
</employees>
</company>
As you can see, the same information is being stored as in the text file, but there's also an indication of
the nature of that information. You know that 29-09-1981 is the BirthDate of Joe Bloggs,
because the data says so. Another benefit of XML is that it can contain multiple types of information in
one document; a fragment like the one below could be inserted after <employees>:
<orders>
<order ID="1">
<product>Staples</product>
<product>Pencils</product>
</order>
<order ID="2">
<product>Biros</product>
<product>Erasers</product>
<order>
</orders>
Using the comprehensive functionality that's built into the XML-handling support provided by the
.NET Framework (and other platforms), retrieving and manipulating the orders separately from the
employees can be accomplished quite easily. This makes it possible to specify an order from the list for
each employee by storing the ID of each order as part of the employee's details:
<employee LastName="Smith" FirstName="John"
BirthDate="05-04-79" Country="UK" Order="2" />