Tags

links:
http://tutorials.jenkov.com/java-xml/sax-example.html

summary:
– SAX parser, we provide handlers, hard to maintain state of related elements
= public class SaxHandler extends DefaultHandler {
= public void startElement
= public void endElement
= public void characters
= startDocument
= startElement

– DOM parser, read in the whole document
= more memory or need to know ahead of time
= Validator available

– Schema, Validator, usable for SAX or DOM
= DOM use Validator.validate(…)
= SAX setSchema(…)
Schema schema = null;
try {
String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
SchemaFactory factory = SchemaFactory.newInstance(language);
schema = factory.newSchema(new File(name));
} catch (Exception e) {
e.printStackStrace();
}

Advertisements