У меня есть полный пример, работающий с там и адаптированный для вашего файла:
public class SaxParserMain {
/**
* @param args
* @throws SAXException
* @throws ParserConfigurationException
* @throws IOException
*/
public static void main(String[] args) throws ParserConfigurationException, SAXException,
IOException {
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
CustomHandler handler = new CustomHandler();
parser.parse(new File("file/scxml.xml"), handler);
}
}
и
public class CustomHandler extends DefaultHandler {
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
System.out.println();
System.out.print("<" + qName + "");
if (attributes.getLength() == 0) {
System.out.print(">");
} else {
System.out.print(" ");
for (int index = 0; index < attributes.getLength(); index++) {
System.out.print(attributes.getLocalName(index) + " => "
+ attributes.getValue(index));
}
System.out.print(">");
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
System.out.print("\n</" + qName + ">");
}
}
Вывод:
<scxml version => 1.0initialstate => startname => calc>
<datamodel>
<data id => exprexpr => 0>
</data>
<data id => resexpr => 0>
</data>
</datamodel>
<state id => start>
<transition event => OPERtarget => opEntered>
</transition>
<transition event => DIGITtarget => operand>
</transition>
</state>
<state id => operand>
<transition event => OPERtarget => opEntered>
</transition>
<transition event => DIGIT>
</transition>
</state>
</scxml>