- The SAXParserFactory class provides the method
- setNamespaceAware(boolean awareness)
for requesting parsers that handle namespaces.
- The domains of namespace prefixes can be traced with the methods
- startPrefixMapping(String prefix, String uri)
- endPrefixMapping(String prefix)
of the ContentHandler interface. The uri argument is irrelevant for this
purpose.
- The URIs of elements can be inspected by the
- startElement(String namespaceURI, String localName,
String qName, Attributes atts)
- endElement(String namespaceURI, String localName, String
qName)
methods of the the ContentHandler interface.
- The URIs of the attributes can be extracted by the
method of the Attributes interface.
public void startElement(String namespace, String localName,
String qName, Attributes atts) {
System.out.print(
qName + " \t uri='" + namespace + "' \t");
for( int i=0; i<atts.getLength(); i++){
System.out.println(
atts.getQName(i) + "(" + atts.getValue(i)
+ "): uri='" + atts.getURI(i) + '\'' );
} }
-_-_-
<?xml version="1.0" encoding="UTF-8"?>
<oranges xmlns="fruit://osu/or" at="1">
<statement at="2"/>
<apples xmlns="fruit://osu/ap" at="3">
<statement at="4"/>
</apples>
<statement at="5"/>
</oranges>
oranges uri='fruit://osu/or' at(1): uri=''
statement uri='fruit://osu/or' at(2): uri=''
apples uri='fruit://osu/ap' at(3): uri=''
statement uri='fruit://osu/ap' at(4): uri=''
statement uri='fruit://osu/or' at(5): uri=''