- Use IE5 to view XML
- Tutorial
- Reference
XML (eXtensible Markup Language)
A language for defining and representing languages.
- HTML is a subset of XML.
- One key use is to define a data structure and data within
the structure, useful for exchanging data between different applications and
computer systems.
- XML gives semantic meaning to data. For example,
<Zip>47150</Zip> can mean the Zip code is 47150.
- Since XML is in text that is readable and writeable by
humans, it is also computer architecture neutral, that is does not depend upon
a specific bit-size representation of floating point numbers for example.
- Many database systems such as Oracle can generate entries
from a database in XML form for use by other applications that understand XML
without regard to the computer system word size, etc.
- XML combined with XSL can separate implementation of the
user interface from the data.
A simple example of XML use is to supply structured data to an
application. Information for shipping a package from one Zip code to another can
be specified in XML with a hierarchy tree as:
<package>
<To>47150</To>
<From>47165</From>
<Weight>17.0</Weight>
<Rate>27.50</Rate>
</package> |
 |
Basic XML Rules
- Hierarchical element structure - XML documents must
have a strictly hierarchical tag structure. That is, start tags must have
corresponding end tags. In XML vocabulary, a pair of start and end tags is
called an element. Any element must be completely nested within
another.
- Well-formed - <To>47150</To>
is well-formed because there is a <To> start tag and a </To> end tag.
- Case sensitive - XML is case sensitive. <to>
47150</To> is invalid.
- Empty - An empty element can
be written as <To></To> or equivalently as <To/>.
- Text - A non-empty element can enclose other
elements or text. <To>47150</To> encloses text of 47150.
- Attribute - <To Signature="Yes">47150</To> has one
attribute, Signature with the value "Yes".
Parsing
Many programming languages and applications such as the IE Web
browser can parse XML to build a hierarchical tree that corresponds to
the XML. For example the following defines XML for Employees. The parser
reads the XML and constructs the corresponding tree. A program such as IE would
use a parser to first construct the tree, then reference nodes on the tree to
access each element of the XML.
<?xml version="1.0"?>
<Employees>
<Employee>
<First>James</First> <Last>Borg</Last>
</Employee>
<Employee>
<First>Joyce</First> <Last>English</Last>
</Employee>
</Employees>
|
|
Parse tree for above XML

|
Exercise 1 - XML
- Copy and paste XML to the Employees.xml.
- Test by loading the Employees.xml file in the
browser.
- Modify the XML file adding an <Age> element and age
text for each employee.
- Test by loading the XML file in the browser.
|
Exercise 2 - XML
- Create a new file Family.xml
- Define XML that corresponds to your family hierarchy as
specified in the tree below.
- Give the person's name, for example: <Name>Ray
Wisman</Name>
- Test by loading the XML file in the browser.
|