Java Reference
In-Depth Information
MySAXHandler handler = new MySAXHandler();
try {
parser.parse(file, handler);
} catch(IOException e) {
e.printStackTrace(System.err);
} catch(SAXException e) {
e.printStackTrace(System.err);
}
}
}
I created the circle.xml file with the content:
<?xml version="1.0"?>
<circle>
<radius>15</radius>
<position>
<x-coordinate>30</x-coordinate>
<y-coordinate>50</y-coordinate>
</position>
</circle>
I saved this in my D :\Beg Java Stuff directory but you can put it wherever you want and adjust the
command line argument accordingly. The command to execute TrySAXHandler with this file is:
java TrySAXHandler "D:/Beg Java Stuff/circle.xml"
On my PC the program produced the output:
Parser will be namespace aware
Parser will validate XML
Parser object is: org.apache.xerces.jaxp.SAXParserImpl@c9ba38
Starting parsing of circle.xml
Start document:
Start element: local name: circle qname: circle uri:
Characters:
Start element: local name: radius qname: radius uri:
Characters: 15
End element: local name: radius qname: radius uri:
Characters:
Start element: local name: position qname: position uri:
Characters:
Start element: local name: x-coordinate qname : x-coordinate uri:
Characters: 30
Search WWH ::




Custom Search