- Forward


Extensible Markup Language
An Introduction


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Basics
Back SMYC Forward
  • What is it?
    • A subset of the Standard Generalized Markup Language (SGML)
    • A meta-language (i.e., it is used to define other languages)
  • Comparison with HTML:
    • HTML is an application of SGML/XML (i.e, a language defined using SGML/XML)
Our View of XML in this Course
Back SMYC Forward
  • HTML is a way of "marking up" papers/articles/books
  • XML is a way of "marking up" hierarchical data (and papers/articles/books each contain hierarchical data)
XML Elements without Components
Back SMYC Forward
  • Syntax:
    • < tag [ attribute =" value " ] ... />
  • An Example:
    • <Caboose id="857-931" type="limited" />
XML Elements with Components
Back SMYC Forward
  • Syntax:
    • < tag [ attribute =" value " ] ... > [ component ... ] </ tag >
  • An Example:
    • <Employee job="Engineer">John Smith</Employee>
  • Note:
    • Tags and attributes are case-sensitive
Attribute or Element?
Back SMYC Forward
  • In General:
    • It depends on how the information will need to be processed
  • A Rule of Thumb:
    • Use attributes for all types that have literals except for large blocks of text
    • Use elements for everything else (avoiding text nodes where possible)
Well-Formed XML Documents
Back SMYC Forward
  • Must only contain elements that have a start tag and a close tag (or must use the abbreviated syntax for empty elements)
  • Must have a single root element
  • Must have the XML declaration <?xml version="1.0" ?> as the first line
An Example
Back SMYC Forward

A Gradebook

xmlexamples/basics/grades-1977.xml
 
A Potential Problem
Back SMYC Forward

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

xmlexamples/namespaces/accounts-payable.xml
 

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

xmlexamples/namespaces/testing.xml
 

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.
Expand
A Potential Problem (cont.)
Back SMYC Forward
  • Namespaces:
    • Can be used by developers to ensure that tags and attributes are unique
    • Are implemented using the xmlns attribute
  • Types:
    • Unqualified - applies to the element that has the xmlns attribute and all of its children
    • Qualified - applied to a particular element
An Example of an Unqualified Namespace
Back SMYC Forward

All of the Tags are Within the Namespace

xmlexamples/namespaces/example-unqualified.xml
 
An Example of a Qualified Namespace
Back SMYC Forward

The Namespace does not Apply to the coursename and coursenumber Elements

xmlexamples/namespaces/example-qualified.xml
 
There's Always More to Learn
Back -