Creating SAX Parsers (continued) |
||
Parsing the XML document and handling events The parser object parses the XML document and generates events. These events are processed by specific elements. The following code parses an XML document, which is specified as a command-line argument. In addition, the code specifies the methods that can count the total number of elements in the XML document. saxParser.parse(new File(argv[0]), new SAXCounter()); } public void startDocument() {count = 0;} public void startElement(String uri, String localName, String qName,Attributes attributes) { count++; public void endDocument() { System.out.println("Total number of elements: " + count); } } |
|
|
Click the Next button to continue. |