The Java API since version 1.4 includes classes for the DOMand SAX approaches and for StAX since 1.6. XML processing is now described into some introductory Java books such as Big Java [25].
XML in a Nutshell [37] provides a short but thorough presentation of these programming models.
Sun publishes excellent online tutorials: [5] for the DOM and SAX processing models and chapter 3 of [72] for the StAX approach. Java & XML [36] is a very good information source for the creation and manipulation of XML documents in Java.
In this chapter, we have used Java to access the content of an XML file, but there are XML parsers for almost every computer languages such as C [62], C++ [64], C# [63], Perl [42] [40], PHP [77], Python [40], Haskell [50], Prolog [53], Ruby [80], even COBOL [21].
In our case, we were dealing similarly with all document nodes without ever looking
at the names of the elements. As it often happens that the information needed in a
document is deep down in the tree, one must then access specific nodes using a sequence
of getFirstChild()
and getNextSibling()
calls until we get to
the right element. This process must often be repeated at each level while it was more
or less implicit using templates and XPath. So we often define special purpose
functions and methods to traverse a specific document tree, but there are other ways.
For example, XMLSpy can generate automatically access methods, in either C++ or
Java, from the the XML Schema that validates a document. This is very useful and much
less error prone that relying on a hand-coded traversal of the tree. When the schema is
changed, then methods can be regenerated and processing of a valid XML will
always follow the structure of the XML Schema. There are also tools to convert
database schemas into XML Schema. So we see that XML processing can be easily
integrated with other systems and languages.