1 / 12

Xerces The Apache XML Project

Xerces The Apache XML Project. Yvonne Yao. Introduction. Set of libraries that provides functionalities to parse XML documents Promotes the use of XML Why? Two types of parsers DOM (Document Object Model) parsers SAX (Simple API for XML) parsers. DOM & SAX. DOM Implements the DOM API

wenda
Download Presentation

Xerces The Apache XML Project

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XercesThe Apache XML Project Yvonne Yao

  2. Introduction • Set of libraries that provides functionalities to parse XML documents • Promotes the use of XML • Why? • Two types of parsers • DOM (Document Object Model) parsers • SAX (Simple API for XML) parsers

  3. DOM & SAX • DOM • Implements the DOM API • Creates a DOM tree in memory • Good for small XML files, or traverse the document back and forth • SAX • Implements SAX API • Event driven interface • Good for huge XML files

  4. Xerces • Implements both DOM and SAX parsers • 3 subprojects • Xerces C++ • Xerces Java • Xerces Perl

  5. Xerces C++ • Current version 2.7.0 • Provides functionalities to read, write, parse, and validate XML documents • Conforms with • XML 1.0 and XML 1.1 • SAX 1.0 and SAX 2.0 • DOM Level 1 and 2

  6. Xerces Perl • Current version 2.7.0 • Implemented using the Xerces C++ API • Provides access to most of the C++ API, except • Functions in the C++ API which have better Perl counterparts (such as file I/O), or • Functions that manipulate internal C++ information that has no role in the Perl module • Conforms to the same set of Standards as Xerces C++

  7. Xerces Java • Xerces Java • Current version 1.4.4 • Conforms with • XML 1.0 • SAX 1.0 and 2.0 • DOM Level 2 • Xerces2 Java • Current version 2.9.0 • Includes Xerces Native Interface, a new framework for building parser components and configurations

  8. Example 1 - DOM <?xml version="1.0" encoding="UTF-8"?> <Personnel> <Employee type="permanent"> <Name>Seagull</Name> <Id>3674</Id> <Age>34</Age> </Employee> <Employee type="contract"> <Name>Robin</Name> <Id>3675</Id> <Age>25</Age> </Employee> <Employee type="permanent"> <Name>Crow</Name> <Id>3676</Id> <Age>28</Age> </Employee> </Personnel>

  9. Example 1 - DOM • Create a DOM object DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); dom = db.parse("employees.xml"); • Get a list of employee elements from DOM Element docEle = dom.getDocumentElement(); NodeList nl = docEle.getElementsByTagName("Employee"); • Get node value from element element.getFirstChild().getNodeValue();

  10. Example 2 - SAX • SAX parsing is event based modeling, it calls a tag handler whenever it encounters a tag public void startElement(String uri, String localName, String qName, Attributes attributes) public void endElement(String uri, String localName, String qName)

  11. Example 2 - SAX • Create a SAX parser SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); sp.parse("employees.xml", this); • Create Employee object when <Employee> is found if(qName.equalsIgnoreCase("Employee")) tempEmp = new Employee(); • Set Employee properties when an end tag is found if (qName.equalsIgnoreCase("Name")) tempEmp.setName(tempVal);

  12. Thank You

More Related