This project is read-only.
Project Description
XML, XML Schema, XSLT, SAX, DOM, XPointer, XQuery

Concepts Includes:

XML Representation and Design

Sample task: write a DTD/XSD that reflects the given XML file
as restrictive as possible.
1. Document Type Definition
• The order of elements
• The number of times an element occurs
• ID attribute
• Element content model or mixed content model
2. XML Schema
• Flat catalogue or hierarchical model
• Simple type or complex type elements
• Data types: string, date, integer….
• Indicators: All, Choice, Sequence, maxOccurs, minOccurs….
• Restriction on values

Accessing XML – XPath

Sample task: write XPath expressions for selecting the
following nodes from the given XML file.
1. Relative or absolute location paths
Start from a specific node or the root node in a document
2. Axes and predicates
13 types of relations, multiple predicates, abbreviations
3. String functions
contains(string, string), starts‐with(string, char)….
4. Boolean functions
5. Node set functions
last(), postion(), count(node‐set), id(object)….

Transforming and Displaying XML – XSLT

Sample task: complete the XSLT below to convert input.xml to
a HTML/XML document that would displayed as Figure 1.
1. xsl:apply‐templates and xsl:template: select and match
2. xsl:for‐each: select every XML element of a specified node‐set
3. xsl:sort: add inside the ?
4. xsl:value‐of: extract the value of an XML element and then ??
5. xsl:if and xsl:choose xsl:when xsl:otherwise: conditional processing
6. More….
use template modes to process certain nodes more than once.
parameter (passed from outside) and variables (defined inside)

Processing XML – DOM

Sample task: complete the DOM code (JAVA or PHP) below,
with the above XML as input OR generate an XML as above.
1. Massive in‐memory tree of nodes
2. Object and methods
3. The XML DOM is a standard for how to
get: getElementsByTagName, getAttribute
change: setAttribute, nodeValue, replaceChild
add: createAttribute, createElement, createTextNode, appendChild
delete: removeChild, removeAttribute
XML elements/attributes.

Processing XML – SAX

Sample task: complete the necessary SAX content handler
methods in Java or PHP, which uses XML Simple API to
generate the displayed output.
The user defines a number of callback methods that will be called when
events occur during parsing. SAX parsing is unidirectional; previously parsed
data cannot be re‐read without starting the parsing operation again.
1. startDocument //Executed at the start of the document
2. endDocument //Executed at the end of the document
3. startElement //Executed at the start of each element
4. endElement //Executed at the end of each element
5. characters //A text node can be sent in one or more
callbacks to this method

Formatting XML – CSS and XSL‐FO

Sample task: use CSS to control formatting; briefly describe
how XSL-FO works.
The XSL‐FO language is an XML‐based language that serves as a functional
superset of CSS. This means that XSL‐FO can do everything CSS can do, and
much more.
1. Displaying XML: Cascading Style Sheets
Specifies a priority scheme to determine which style rules apply if
more than one rule matches against a particular element.
Screen displaying
Choice of font, size, color and emphasis for elements.
2. Printing from XML: XSL Formatting Objects
Page printing
How it works?

Linking in XML – XLink and XPointer

Sample task: write an XLink expression using XPointer to
refer to the element in the target document.
1. Xlink attribute
xlink:actuate //Defines when the linked resource is read and shown
xlink:href //The URL to link to
xlink:show //Where to open the link. Replace is default
xlink:type //The type of link
To get access to the XLink attributes and features we must declare the
XLink namespace at the top of the document.
2. XPointer
Navigate (with an XPath expression) to a specific place in the document.

Querying XML – XQuery

Sample task: (1) show the XML that will be selected by the
following Xquery; OR (2) write an Xquery to “select the title of
all CD records with a price less than $10 from the CD
collection stored in the XML document called cd_catalog.xml”.

for $x in doc("cd_catalog.xml")/CDcollection/CD
where $x/price<10
order by $x/title
return $x/title

XML Schema is more powerful and more precise than XML DTD in many ways:

1. Strong Typing:
In a DTD, we do not have a choice for constraining all the elements and attributes.
An element in DTD can be described in one of the four ways: EMPTY, ANY, Mixed or Text Content. There is no other way to represent an integer, date etc.

In XML Schema we can make the elements strongly typed, can also ber allowed to set a range or value pattern.

2. XML Schemas are themselves XML documents. They reference the XML Schema Namespace, and even have their own DTD.

<xs:element name="CardID">


<xs:attribute name="id" type="xs:ID" use="required" />



From here we can see that the xml schema document can be defined in terms of its restrictions, pattern values, their sequence, their base type, minOccurs, maxOccurs.
But in DTD these options are not present and so XML Schema provides more sense and clear picture related to the schema.

So, in this schema document:
It can be specified the id attribute which only relates to the ID of the Card and hence can not be duplicated.
But in DTD this id will work but can contains the duplicate values.


1. Create an English-Spanish bilingual lexicon to be used for movie, novel,
and artwork title-translation. Your translation resource is updated on monthly basis by your
data providers

Task 1: XML to XML transformation
You are going to deliver an English-Spanish bilingual lexicon to your business partners in
Dublin and Alicante. Your task is to create XSLT stlyesheet translation.xslt that
results in a bilingual dictionary translation.xml in XML format.
In this dictionary, each search term is unique; each translation is a one-to-many
translation pair, if there are multiple unique replace terms available in wordlist.xml;
where counter is the total number of unique replace terms for each search term. The
attribute initial is associated with the element translation; the value of initial is
the initial letter of the search term. Note: Duplicates are NOT allowed. Empty elements
are NOT allowed.

Task 2: XML to HTML transformation
You are going to make the English-Spanish bilingual dictionary publicly available on the
intranet, and allow the business partners to browse the dictionaries alphabetically. Your task
is to use the output from Task 1 translation.xml as the input; create XSLT stylesheet
dictionary.xslt to generate a HTML file dictionary.

CSS to control formatting:
Heading ("Browse by letter:"): in blue, font size of 20.
Search terms: bold, font size of 16, the background colour is #FFC.
Replace terms: italic, font size of 14.
CSS code must be kept in an external CSS file dictionary.css, this file is then referenced in your HTML using the <link> instead of <style>.

2. SAX (Simple API for XML) and DOM (Document Object Model) are two dramatically
different APIs for accessing information in XML documents. Task is to write Java or
PHP programs to process XML documents using SAX and DOM.

Last edited Oct 17, 2010 at 3:09 AM by pgargaupp, version 5