Académique Documents
Professionnel Documents
Culture Documents
n How can applications use XML processors? n An interface for “plugging-in” and using XML
– A Java-based answer: through JAXP processors in Java applications
– includes packages
– An overview of the JAXP interface
» org.xml.sax: SAX 2.0 interface
» What does it specify?
» org.w3c.dom: DOM Level 2 interface
» What can be done with it?
» javax.xml.parsers:
» How do the JAXP components fit together?
initialization and use of parsers
[Partly based on tutorial “An Overview of the APIs” available at » javax.xml.transform:
http://java .sun.com/xml/jaxp/dist/1.1/docs/tutorial/overview initialization and use of transformers
/3_apis.html, from which also some graphics are borrowed] (XSLT processors)
n Included in JDK starting from vers. 1.4
SDPL 2002 Notes 3: XML Processor Interfaces 1 SDPL 2002 Notes 3: XML Processor Interfaces 2
JAXP: XML processor plugin (1) JAXP: XML processor plugin (2)
SDPL 2002 Notes 3: XML Processor Interfaces 3 SDPL 2002 Notes 3: XML Processor Interfaces 4
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
SDPL 2002 Notes 3: XML Processor Interfaces 5 SDPL 2002 Notes 3: XML Processor Interfaces 6
1
JAXP: Using an SAX parser (1) JAXP: Using an SAX parser (2)
getXMLReader
n We’ve already used this:
SAXParserFactory spf =
SAXParserFactory.newInstance();
XML try {
SAXParser saxParser = spf.newSAXParser ();
XMLReader xmlReader =
saxParser.getXMLReader ();
} catch (Exception e) {
System.err.println(e.getMessage());
System.exit(1);
};
SDPL 2002 Notes 3: XML Processor Interfaces 7 SDPL 2002 Notes 3: XML Processor Interfaces 8
JAXP: Using a DOM parser (1) JAXP: Using a DOM parser (2)
SDPL 2002 Notes 3: XML Processor Interfaces 9 SDPL 2002 Notes 3: XML Processor Interfaces 10
2
JAXP Transformation API JAXP: Using Transformers (1)
SDPL 2002 Notes 3: XML Processor Interfaces 13 SDPL 2002 Notes 3: XML Processor Interfaces 14
Serializing a DOM Document as XML text Other Java APIs for XML
SDPL 2002 Notes 3: XML Processor Interfaces 17 SDPL 2002 Notes 3: XML Processor Interfaces 18
3
JAXP: Summary