120 likes | 280 Views
XML Apache Tools Parsing and Transformation. Andy Clark. Apache XML Parsers. Xerces Versions available in Java, C++, and Perl* Xerces-J Supports various programming APIs JAXP, DOM, SAX, XNI Support standards XML+DTD, Namespaces, XML Schema, etc….
E N D
XML Apache ToolsParsing and Transformation Andy Clark 30 May 2002
Apache XML Parsers • Xerces • Versions available in Java, C++, and Perl* • Xerces-J • Supports various programming APIs • JAXP, DOM, SAX, XNI • Support standards • XML+DTD, Namespaces, XML Schema, etc… * The Perl version is a wrapper on the C++ version.
Xerces-J • Download • Location: http://xml.apache.org/dist/xerces-j/ • Packages: binary, source, and tools • NOTE: Users only need binary distribution • Contents • Jar files • xmlParserAPIs.jar, xercesImpl.jar, xercesSamples.jar • Documentation • Samples
DOM samples dom.Counter dom.Writer …etc… SAX samples sax.Counter sax.DocumentTracer sax.Writer XNI samples xni.Counter xni.DocumentTracer xni.Writer …etc… Xerces-J Samples
Xerces-J SAX Example #1 • sax.Counter 01 > java –cp xmlParserAPIs.jar;xercesImpl.jar;xercesSamples.jar sax.Counter data/personal.xml 02 data/personal.xml: 21 ms (38 elems, 20 attrs, 145 spaces, 128 chars)
Xerces-J SAX Example #2 • sax.DocumentTracer 01 > java –cp xmlParserAPIs.jar;xercesImpl.jar;xercesSamples.jar sax.DocumentTracer data/personal.xml 02 setDocumentLocator(locator= {cut}) 03 startDocument() 04 startDTD(name="personnel", publicId=null, systemId="personal.dtd") 05 startEntity(name="[dtd]") 06 elementDecl(name="personnel", contentModel="(person)+") … 23 endDTD() 24 startElement(uri="", localName="personnel", qname="personnel", attributes={}) 25 ignorableWhitespace(text="\n\n ") 26 …
Xerces-J SAX Example #3 • sax.Writer 01 > java –cp xmlParserAPIs.jar;xercesImpl.jar;xercesSamples.jar sax.Writer data/personal.xml 02 <?xml version="1.0" encoding="UTF-8"?> 03 <personnel> 04 05 <person contr="false" id="Big.Boss"> 06 <name><family>Boss</family> <given>Big</given></name> 07 <email>chief@foo.com</email> 08 <link subordinates="one.worker two.worker three.worker four.worker five.worker"></link> 09 <friend idref="f1"></friend> 10 </person> …
Apache XSLT Transformers • Xalan • Versions available in Java and C++ • Xalan-J • Supports standard programming APIs • TrAX • Support standards • XSLT, XPath
Xalan-J • Download • Location: http://xml.apache.org/dist/xalan-j/ • Packages: binary and source • NOTE: Users only need binary distribution • Contents • Jar files • NOTE: Bundles Xerces-J jar files • Documentation • Samples
Xalan-J Example • org.apache.xalan.xslt.Process 01 > java –cp bin/xml-apis.jar;bin/xalan.jar;bin/xercesImpl.jar org.apache.xalan.xslt.Process –IN xdocs/sources/xalan/index.xml –XSL xdocs/style/stylesheets/document2html.xsl 02 <html> 03 <head> 04 <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> 05 <script src="resources/script.js" type="text/javascript“ language="JavaScript"></script> 06 <title>Xalan-Java version 2.3.0</title> …
Useful Links • Apache XML Project • http://xml.apache.org/ • Xerces-J • http://xml.apache.org/xerces2-j/ • Xalan-J • http://xml.apache.org/xalan-j/
XML Apache ToolsParsing and Transformation Andy Clark