background image

Resources, Namespaces, and Errors

<< XMLOutputFactory Class | XMLStreamReader Methods >>
<< XMLOutputFactory Class | XMLStreamReader Methods >>

Resources, Namespaces, and Errors

Resources, Namespaces, and Errors
The StAX specification handles resource resolution, attributes and namespace, and errors and
exceptions as described below.
Resource Resolution
The XMLResolver interface provides a means to set the method that resolves resources during
XML processing. An application sets the interface on XMLInputFactory, which then sets the
interface on all processors created by that factory instance.
Attributes and Namespaces
Attributes are reported by a StAX processor using lookup methods and strings in the cursor
interface, and Attribute and Namespace events in the iterator interface. Note here that
namespaces are treated as attributes, although namespaces are reported separately from
attributes in both the cursor and iterator APIs. Note also that namespace processing is optional
for StAX processors. See the StAX specification for complete information about namespace
binding and optional namespace processing.
Error Reporting and Exception Handling
All fatal errors are reported by way of the javax.xml.stream.XMLStreamException interface.
All nonfatal errors and warnings are reported using the javax.xml.stream.XMLReporter
interface.
Reading XML Streams
As described earlier in this chapter, the way you read XML streams with a StAX processor, and
what you get back, vary significantly depending on whether you are using the StAX cursor API
or the event iterator API. The following two sections describe how to read XML streams with
each of these APIs.
Using XMLStreamReader
The XMLStreamReader interface in the StAX cursor API lets you read XML streams or
documents in a forward direction only, one item in the infoset at a time. The following methods
are available for pulling data from the stream or skipping unwanted events:
Get the value of an attribute
Read XML content
Determine whether an element has content or is empty
Get indexed access to a collection of attributes
Get indexed access to a collection of namespaces
Using StAX
Chapter 18 · Streaming API for XML
561