CP C.P. 6128, Succ. Centre-Ville
Montréal, Québec
Canada H3C 3J7
lapalme@iro.umontreal.ca
http://www.iro.umontreal.ca/~lapalme/ForestInsteadOfTheTrees/
August 01, 2022
Abstract
This tutorial gives a high-level overview of the main principles underlying some XML technologies: DTD, XML Schema, RELAX NG, Schematron, XPath, XSL stylesheets, Formatting Objects, DOM, SAX and StAX models of processing. They are presented from the point of view of the computer scientist, without the hype too often associated with them. We do not give a detailed description but we focus on the relations between the main ideas of XML and other computer language technologies. A single compact pretty-print example is used throughout the text to illustrate the processing of an XML structure with XML technologies or with Java programs. We also show how to create an XML document by programming in Java, in Ruby, in Python, in PHP, in JavaScript and in Swift.
The source code of the example XML files and the programs are available either at the companion web site of this document or by clicking on the file name within brackets at the start of the caption of each example. The source file will then be shown in a web page or in a new tab of the browser. Should the page be interpreted by the browser, the reader can ask for the source of the page.
The writing of this XML tutorial started in the Fall of 2002 during my sabbatical at the Université de Grenoble and at Xerox Research Centre Europe. I wish to thank Gilles Sérasset, Christian Boitet, Pierre Isabelle and Marc Dymetman for many fruitful discussions.
Since then, the document has been improved (at least it has increased in the number of pages...) after having used it in teaching undergraduate and graduate courses at the Université de Montréal: IFT3225 and IFT6281. I especially thank Fabrizio Gotti for his careful proofreading and many insightful comments.
In 2007, I decided to start practicing what I preach by using XML technologies for the organization of the manuscript of this tutorial. Fabrizio Gotti converted the original LaTeX files to DocBook so that now PDF and HTML versions can be produced from a single set of XML source files.
Table of Contents
List of Figures
Wine.xml
]JTree
display of Example 2.2List of Tables
List of Examples
CellarBook.xml
including
WineCatalog.xml
in a different namespaceCellarBook.xml
, the XML instance document holding the content
of the cellarWineCatalog.xml
NamespaceExample.xml
] A simplistic example of declaration and use of namespaces CellarBook.dtd
] DTD for the cellar book, validation of the
instance file in
Example 2.2
WineCatalog.dtd
] DTD to validate the wine catalog, included
in
Example 3.1
CellarBook.xsd
] XML Schema for the cellar book, validation of the
instance file in
Example 2.2.WineCatalog.xsd
] XML Schema file to validate the instance
document shown in
Example 2.3.
CellarBook.xsd
importing
Example 3.4
in a different namespace.CellarBook.rnc
] RELAX NG Compact schema for the cellar book to validate
Example 2.2.
WineCatalog.rnc
] RELAX NG Compact schema for the wine catalog to
validate
Example 2.3
CellarBook.sch
] ISO-Schematron for the cellar book to validate
Example 2.2.WineCatalog.xsl
] XSLT stylesheet to select the red wines in the
catalogCellarBook.xsl
] XSLT stylesheet to produce information
about the cellarbuilt-in-template-rules.xsl
] Built-in template rules for XSLT.compactHTML.xsl
] XSLT transformation to produce a bulleted
list from the cellar bookcompact.xsl
]: Stylesheet used to transform Example 2.2 into
Example 5.8compactFO.xsl
] Transformation of
the cellar book into a colored nested blocks representationcompact.css
] for displaying the content of the cellar bookWineCatalog.xq
] XQuery script to select the red wines in the
catalogCellarBook.xq
] XQuery script to produce information
about the cellarcompactHTML.xq
] XQuery transformation to produce a bulleted
list from the cellar bookcompact.xq
]: Stylesheet used to transform Example 2.2 into
Example 5.8CBWC-RDF-S.rdf
] Subject, Predicate and Object triples for the
cellar book in RDF/XML. CBWC-RDF-S.ttl
] The Turtle version of Example 7.1
CBWC-RDF-S.rq
] SPARQL queries on Example 7.2
DOMCompact.java
] Text compaction of the cellar book
with Java using the DOM modelCompactErrorHandler.java
] Error handler of the DOM
parsing of Example 8.1SAXCompact.java
] Text compaction of the cellar book
with Java using the SAX modelCompactHandler.java
] SAX handler for text
compacting an XML file such as Example 2.2StAXCompact.java
] Text compaction of the cellar book
with Java using the SAX modelTreeViewer.java
]: JTree
building with
DOM and StAX Processing of an XML fileJTreeHandler.java
]: JTree
building with
SAX Processing of an XML fileCompactTokenizer.java
]: Specialized stream
tokenizer that ignores blank tokensDOMExpand.java
]: Compact form parsing to create a
DOM XML document SAXExpand.java
]:
XML document creation using SAX eventsCompactReader.java
]: Compact
form parsing to generate SAX eventsStAXExpand.java
]:
XML document creation using the StAX approachDOMCompact.rb
] Text compaction of the cellar book
with ruby using the DOM modelSAXCompact.rb
] Text compaction of the cellar book
with ruby using the SAX modelCompactHandler.rb
] Ruby SAX handler for text
compacting Example 2.2CompactTokenizer.rb
] Specialized string scanner that
returns tokens of compact form.DOMExpand.rb
] Ruby compact form parsing to create an
XML document DOMCompact.py
] Text compaction of the cellar book
with Python using the DOM modelSAXCompact.py
] Text compaction of the cellar book
with python using the SAX modelCompactHandler.py
] Python SAX handler for text
compacting Example 2.2XMLStreamReader.py
] Text compaction of the cellar book
with Python using the SAX modelStAXCompact.py
] Text compaction of the cellar book
with Python using the StAX modelCompactTokenizer.py
] Specialized string scanner that
returns tokens of compact form.DOMExpand.py
] Python compact form parsing to create an
XML document ETCompact.py
] Python compaction of an XML file
using ElementTree
nodes. ETExpand.py
] Python compact form parsing to create a
ElementTree
document DOMCompact.php
] Text compaction of the cellar book
with php using the DOM modelcompactHTML.php
] HTML compaction of the cellar book
with PHP using the DOM modelSAXCompact.php
] Text compaction of the cellar book
with php using the SAX modelCompactHandler.php
] PHP SAX handler for text
compacting Example 2.2StAXCompact.php
] Text compaction of the cellar book
with PHP using the SAX modelCompactTokenizer.php
] Specialized string scanner that
returns tokens of compact form.DOMExpand.php
] PHP compact form parsing to create an
XML document XSLcompact.php
] PHP compaction of an XML file using an
XSLT stylesheet.SimpleXMLPath.php
] SimpleXML file loading followed by PHP
SimpleXML
expressionsSimpleXMLCompact.php
] PHP compaction of an XML file
using a SimpleXML
. SimpleXMLExpand.php
] PHP compact form parsing to create a
SimpleXMLElement
document DOMCompact.js
] Text compaction of the cellar book
with JavaScript using the DOM modelCompactTokenizer.js
] JavaScript specialized string scanner that
returns tokens of compact formDOMExpand.js
] JavaScript compact form parsing in order to create
an XML document DOMCompact.swift
] Text compaction of the cellar book
with Swift using the DOM modelSAXCompact.swift
] Text compaction of the cellar book
with swift using the SAX modelDOMExpand.swift
] Swift compact form parsing to create an
XML document DOMCompact.as
] Text compaction of the cellar book
with E4X using the DOM modelCompactTokenizer.as
] E4X specialized string scanner that
returns tokens of compact formDOMExpand.as
] E4X compact form parsing in order to create
an XML document WineList.xml
] A small wine list in XMLWineList.json
] A small wine list in JSONxml2json.xsl
] XSLT stylesheet to convert an XML
file into JSON. WineList.yaml
] YAML version of Example 10.35DBTemplates.xml
] Examples of the most common uses of DocBook 5
elements in this document.The writing of this XML tutorial started in the Fall of 2002 during my sabbatical at the Université de Grenoble and at Xerox Research Centre Europe. I wish to thank Gilles Sérasset, Christian Boitet, Pierre Isabelle and Marc Dymetman for many fruitful discussions.
Since then, the document has been improved (at least it has increased in the number of pages...) after having used it in teaching undergraduate and graduate courses at the Université de Montréal: IFT3225 and IFT6281. I especially thank Fabrizio Gotti for his careful proofreading and many insightful comments.
In 2007, I decided to start practicing what I preach by using XML technologies for the organization of the manuscript of this tutorial. Fabrizio Gotti converted the original LaTeX files to DocBook so that now PDF and HTML versions can be produced from a single set of XML source files.