SAX Tutorial 1
From Progzoo
To make a SAX program work you need to implement a ContentHandler as specified: http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html see also http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE stock [
<!ELEMENT stock (item*)>
<!ELEMENT item EMPTY>
<!ATTLIST item id ID #REQUIRED
legend CDATA #REQUIRED
price CDATA #REQUIRED>
]>
<stock>
<item price="50" legend="Pr-Burger" id="E1" />
<item price="15" legend="Crisp S+V" id="E5" />
<item price="15" legend="Crisp C+O" id="E6" />
<item price="50" legend="Flat Cola" id="E7" />
</stock>
SAX Using startElement
Use the phrase localName.equals("someString") to print the legend for the item nodes only.
The NodeCounter program is shown.
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
Node Counting
Use the phrase nodeName.equals("someString") to count only the item elements.
The NodeCounter program is shown.
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
Node Counting
For the item elements print the sequence number, the legend and the price:
1 Pr-Burger 50 2 Crisp S+V 15 3 Crisp C+O 15 4 Flat Cola 50
The NodeCounter program is shown.
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]