Introduction to XML
Computing Resources >>Tutorials >> Web Development >> Introduction to XML  

 

How Can XML be used?

In the previous example, we saw five user-defined elements: “letter”, “to”, “from”, “greeting”, and “body”. Unlike HTML, these values will not display in a web browser if we load our XML document. If you want to display XML values, XML must be “embedded” in an HTML document. For instance, XML can be embedded in a “data island” which looks like this:

<xml id="letter">
<letter>
<to>Buddy</to>
<from>Fran</from>
<greeting>Howdy!</greeting>
<body>Don't forget me this weekend!</body>
</letter>
</xml>

This XML data can then be “bound” to HTML elements to display in a web browser by building a table in HTML and populating it with XML elements, like this:

<html>
<body>

<xml id="letter">
<letter>
<to>Buddy</to>
<from>Fran</from>
<greeting>Howdy!</greeting>
<body>Don't forget me this weekend!</body>
</letter>
</xml>

<table border="1" datasrc="#letter">
<tr>
<td><span datafld="to"></span></td>
<td><span datafld="from"></span></td>
</tr>
</table>

</body>
</html>

When you display this HTML document in a browser, you will see this:

You may ask, “So what good is that? Why not simply use HTML to display these values?”

This is where the advantages of XML really become apparent. If two user’s applications use the same elements, they can exchange information between each other.

For instance, if another user’s application also has an element labeled “letter” with a child element labeled “from”, they could also display the value “Howdy!” by referring to the Internet address of User A’s XML document:

In this sense, XML is a tool for exchanging data. XML documents with the same elements can “pass” data to each other, and multiple users can form a sort of “data network” that can be used to store, update, and display information from multiple sites and addresses.

 

next section>

 

Watch the video
screenshot
choose format/speed
real media dial-up | broadband

Tutorial Transcript

© 2003 Andrew Loomis| iSchool | UT Austin | webmaster