542. XML Programming Using Java
Rev. 1.4
This
four-day course builds skills in Java’s XML processing APIs – chiefly parsing
using SAX and DOM and transformations using XSLT, all using the Java API for XML
Processing, or JAXP. It
also covers the newer Java API for XML Binding, or JAXB, which standardizes
serialization according to XML Schema. The course is intended for
students with a working knowledge of XML – and possibly DTDs or XML Schema – who
want to build XML applications or components using the Java language. Everything in the course
adheres to W3C and Java standards for completely portable code.
The first
module introduces the JAXP and the two main Java APIs for parsing XML documents: SAX and the DOM. Students learn the basic JAXP
architecture and how to create parsers that expose SAX or DOM APIs, and how to
configure parsers according to the SAX features and properties specification. SAX parsing is covered, working
from simple SAX event handling through patterns for understanding document
content from event sequences, to error handling and document validation. Students then learn how to read
document information using the DOM’s tree model and API, and move on to using
the DOM to modify and to create new documents and information nodes. The final two chapters of this
module cover the DOM2 Traversal and Events modules and the JAXB, with a focus on
XML serialization and persistence.
The second
module introduces students to the XPath and
XSLT specifications, and how to use JAXP as an interface to XML transformations. Students learn the basic JAXP Transformer architecture, develop
fluency in the exacting but powerful XPath syntax,
and then build a number of XSLT transformations. Study of XSLT is arranged first
to develop control over output production, including a solid understanding of
the sometimes mysterious built-in template rules, template matching, priority
and modes, and control of whitespace production. Then students turn towards the
source document and learn to extract single values, to make shallow and deep
copies of source elements, to use variables, and to use flow-control constructs
to effect conditional processing and loops. In the module’s final case
study, students build a servlet-based Web application that uses JAXP and XSLT
to produce dynamic content based on an XML data source.
Learning
Objectives
· Understand the use of SAX and
DOM APIs for XML parsing.
· Understand the need for JAXP
as an additional layer to the standard contract between applications and
parsers.
· Use JAXP to write entirely
portable XML parsing code.
· Parse element and attribute
content, processing instructions, and other document information using SAX.
· Parse documents using the DOM.
· Modify, create and delete
information in an XML document using the DOM.
· Use DOM Traversal to simplify
and make parsing algorithms more effective.s
· Use DOM Mutation Events to
track changes to an XML document.
· Use the JAXB to generate
persistent Java object models based on XML Schema.
· Implement XML persistence
using the JAXB.
· Write simple and complex
queries into XML document content using XPath.
· Use XSLT for XML-to-XML
transformations.
· Use the built-in template
rules correctly to process the right source information.
· Use mode and priority to
control template matching.
· Control exact production of
text, HTML and XML elements, and whitespace.
· Derive source document content
and make copies of node trees.
· Use looping and conditional
processing to manage output production.
· Build J2SE and Web
applications that leverage XSLT transformation logic.
Prerequisites:
· Experience in Java
Programming.
· Basic understanding of XML is
required.
· XML Schema is used
peripherally in the course, and knowledge of this technology will be helpful,
but is not required.
Course
Outline
MODULE 1 – XML
PARSING USING JAVA
1. The Java API for XML
Processing (JAXP)
a. Parsing XML
b. SAX and DOM
c. What the W3C Says
d. What the W3C Doesn't Say
e. Sun and Apache
f. JAXP
g. Parser Factories
h. Pluggable Parsers
i. Parser Features and Properties
2. The Simple API for XML (SAX)
a. Origins of SAX
b. The SAX Parser
c. The SAX Event Model
d. Reading Document Content
e. Handling Namespaces
f. SAX Features for Namespaces
g. Parsing Attributes
h. Error Handling
i. DTD Validation
j. Schema Validation
k. Handling Processing
Instructions
3. The Document Object Model
(DOM)
a. Origins of the DOM
b. DOM Levels
c. DOM2 Structure
d. The Document Builder
e. DOM Tree Model
f. DOM Interfaces
g. Document, Node and NodeList Interfaces
h. Element and Text Interfaces
i. Finding Elements By Name
j. Walking the Child List
k. The Attribute Interface
l. Traversing Associations
m. The JAXP Transformer Class
n. Sources and Results
o. Combining SAX and DOM
Processing
p. Namespaces and the DOM
4. Manipulating XML Information
with the DOM
a. Modifying Documents
b. Modifying Elements
c. Modifying Attributes
d. Managing Children
e. Seeking a Document Location
f. The ProcessingInstruction Interface
g. Creating New Documents
5. DOM Level 2 Modules
a. DOM Traversal
b. The DocumentTraversal Interface
c. Node Filters
d. The NodeIterator Interface
e. The TreeWalker Interface
f. DOM Ranges
g. DOM Events
h. Mutation Events
i. Handling Events
j. Event Flow
k. Capturing and Bubbling
l. Cancelable Events
6. XML Serialization and the Java
API for XML Binding (JAXB)
a. XML for Object Persistence
b. Persistence Strategies
c. The Memento Pattern
d. Deserialization with SAX
e. Object Persistence with the
DOM
f. Adapting Object Models to the
DOM
g. The Java API for XML Binding
h. Marshalling, Unmarshalling,
and Validation
i. Schema as Object Models
j. UML for XML
k. Mapping XML to Java: Simple Types, Complex Types,
and Collections
l. Object Factories
m. Customizing JAXB Bindings
n. The DOM vs. JAXB
o. JAXB for Persistence
p. Automatic Translation
MODULE 2 – XML
TRANSFORMATIONS USING JAVA
1. Using the JAXP for
Transformations
a. XPath, XSLT and Java
b. The Transformer Class
c. The TransformerFactory Class
d. Sources and Results
e. Identity Transformations
f. Creating Transformations from Stylesheets
g. Template Parameters
h. Output Methods and Properties
2. XPath
a. Use of XPath in Other XML Technologies
b. XPath Expressions
c. The Axis
d. The Node Test
e. The Predicate
f. XPath Types
g. XPath Functions
h. Implied Context
i. Querying with XPath
j. XPath and the DOM
3. Templates and Production
a. Rule-Based Transformations
b. Templates and Template
Matching
c. Built-In Template Rules
d. Recursion Through Templates
e. Template Context
f. Output Methods
g. Controlling Whitespace
h. Literal Replacement Elements
i. Formalizing Text, Elements and
Attributes
j. Defining Target Vocabulary
k. Generating Processing
Instructions
4. XSLT: Dynamic Content and Flow
Control
a. Web Applications Using XSLT
b. J2EE and JAXP
c. Deriving Source Content
d. Getting Source Values
e. Attribute Value Templates
f. Copying Source Elements and
Trees
g. Looping
h. Conditionals
Appendix A Learning Resources
Appendix B Quick Reference: W3C Namespaces
Appendix C UML for XML Schema
Appendix D Quick Reference: XML and DTD Grammar
Appendix E Quick Reference: XPath and XSLT
Software: All free downloadable tools