JMU
Extensible Markup Language
An Introduction


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Basics
Our View of XML in this Course
XML Elements without Components
XML Elements with Components
Attribute or Element?
Well-Formed XML Documents
An Example

A Gradebook

xmlexamples/basics/grades-1977.xml
<?xml version="1.0"?>
<GRADES>
  <STUDENT>
     <NAME>Kim Maschino</NAME>
     <ID>321-00-0021</ID>
     <GRADE>A+</GRADE>
  </STUDENT>
  <STUDENT>
     <NAME>Doug Sideler</NAME>
     <ID>001-31-9998</ID>
     <GRADE>B</GRADE>
  </STUDENT>
  <STUDENT>
     <NAME>Wayne Tromer</NAME>
     <ID>100-23-4167</ID>
     <GRADE>C</GRADE>
  </STUDENT>
</GRADES>
        
A Potential Problem

Imagine that you had developed an accounts payable database that contained the following:

xmlexamples/namespaces/accounts-payable.xml
<?xml version="1.0"?>
<payments>
  <payment>
    <amount>21.35</amount>
    <check bank="157-1" >150</check>
  </payment>
</payments>
        

Also, imagine someone at another organization developed a testing database that included the following:

xmlexamples/namespaces/testing.xml
<?xml version="1.0"?>
<testing>
  <validation>
    <check location="store">
      <checker>Mary Jones</checker>
    </check>
  </validation>
</testing>        

What problem would arise if you wanted to combine the two systems so that payments could be validated?

The two systems use both use a "check" tag but use it in different ways.
A Potential Problem (cont.)
An Example of an Unqualified Namespace

All of the Tags are Within the Namespace

xmlexamples/namespaces/example-unqualified.xml
<?xml version="1.0"?>
<syllabus xmlns="http://www.cs.jmu.edu/users/bernstdh/">
  <header>
    <coursename>Introduction to XML</coursename>
    <coursenumber>CS000</coursenumber>
  </header>
  <body>
    <title>Course Overview</title>
  </body>
</syllabus>
        
An Example of a Qualified Namespace

The Namespace does not Apply to the coursename and coursenumber Elements

xmlexamples/namespaces/example-qualified.xml
<?xml version="1.0"?>
<syllabus xmlns:dhb="http://www.cs.jmu.edu/users/bernstdh/">
  <dhb:header>
    <coursename>Introduction to XML</coursename>
    <coursenumber>CS000</coursenumber>
  </dhb:header>
  <dhb:body>
    <dhb:title>Course Overview</dhb:title>
  </dhb:body>
</dhb:syllabus>