Java Reference
In-Depth Information
21.3.2 XML parsers
We 've only touched the surface of XML syntax. XML documents can become
very long and complex. In fact, long XML documents become almost anything
but human readable. Only the most determined (and perhaps demented) human
will want to read through a complex XML document. The good thing about XML
is that the syntax is very well defined and strict, which makes parsing by computer
straightforward. Obviously, the casual programmer does not want to have to write
code to parse long and ugly XML documents. Thankfully, the computing industry
has already provided many XML parsing libraries for a variety of languages,
including Java.
There are two basic ways to do XML parsing. One is to read an XML doc-
ument into the parser and set up the parser so that it makes callbacks to certain
handlers each time a tag is seen. This technique is known as the Simple API
for XML, or SAX. The other method is to read in the entire document and
build a structure in memory that represents the structure of the document. Then
the values associated with the various tags in the document can be accessed in a
structured way, reminiscent of the way Java handles instance variables in a deeply
nested object hierarchy. This scheme is known as the Document Object Model, or
DOM [5-7].
There are a variety of implementations of both the SAX and DOM models.
Java includes both SAX and DOM parsers as part of the standard Java installa-
tion (in the org.xml.sax and org.w3c.dom packages, respectively). These
and other Java XML technologies are grouped together under the term Java API
for XML Processing, or JAXP. Space does not permit discussing these tools, but
there are good online tutorials [3]. There you will also find optional Java technolo-
gies that support web services development. These are discussed in more detail
below.
XML parsers provide many benefits, not the least of which is relieving you
of having to parse a complex XML document yourself. Parsers can also check a
document for conformance to the DTD or Schema that the document should be
using. Documents that adhere to the DTD or Schema are said to be conforming
documents. Invalid or non-conforming documents can be rejected at the outset
of processing by the parser rather than waiting for some hard-to-find error much
later while a server is performing operations on the data.
21.4 Java web services
So far we've explained, briefly, what web services are and how XML documents
are used. But we have not described how to actually implement a client/server
application using the web services paradigm. This section provides an intro-
duction to doing just that. Again, the subject is large and encompasses many
technologies that we do not have the space to discuss here. So we just introduce
the important features and tools and provide pointers to more information.
Search WWH ::




Custom Search