Java Reference
In-Depth Information
XMLStreamReader
also declares various methods for extracting infoset inform-
ation. For example,
QName getName()
returns the qualified name (as a
javax.xml.namespace.QName
instance) of the element at the cursor position
when
next()
returns
XMLStreamReader.START_ELEMENT
or
XMLStreamReader.END_ELEMENT
.
Note
QName
describes a qualified name as a combination of namespace URI,
localpart,andprefixcomponents.Afterinstantiatingthisimmutableclass(viaacon-
structor such as
QName(String namespaceURI, String localPart,
String prefix)
),youcanreturnthesecomponentsbycalling
QName
's
String
getNamespaceURI()
,
String getLocalPart()
, and
String getPre-
fix()
methods.
XML document's start and end elements via a stream-based reader.
Listing 10-16.
StAXDemo
(version 1)
import java.io.FileNotFoundException;
import java.io.FileReader;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
class StAXDemo
{
public static void main(String[] args)
{
if (args.length != 1)
{
System.err.println("usage:
java
StAXDemo
xml-
file");
return;
}
try
{