XML

powered by FreeFind
Modified: 

XML (eXtensible Markup Language) 

A language for defining and representing languages. 

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

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

  1. Copy and paste XML to the Employees.xml.
  2. Test by loading the Employees.xml file in the browser.
  3. Modify the XML file adding an <Age> element and age text for each employee.
  4. Test by loading the XML file in the browser.

Exercise 2 - XML

  1. Create a new file Family.xml
  2. Define XML that corresponds to your family hierarchy as specified in the tree below.
  3. Give the person's name, for example: <Name>Ray Wisman</Name>
  4. Test by loading the XML file in the browser.