Presentation is loading. Please wait.

Presentation is loading. Please wait.

Xerces The Apache XML Project Yvonne Yao. Introduction Set of libraries that provides functionalities to parse XML documents Set of libraries that provides.

Similar presentations


Presentation on theme: "Xerces The Apache XML Project Yvonne Yao. Introduction Set of libraries that provides functionalities to parse XML documents Set of libraries that provides."— Presentation transcript:

1 Xerces The Apache XML Project Yvonne Yao

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

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

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

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

6 Xerces Perl Current version 2.7.0 Current version 2.7.0 Implemented using the Xerces C++ API Implemented using the Xerces C++ API Provides access to most of the C++ API, except 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 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 Functions that manipulate internal C++ information that has no role in the Perl module Conforms to the same set of Standards as Xerces C++ Conforms to the same set of Standards as Xerces C++

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

8 Example 1 - DOM <Personnel> Seagull Seagull <Id>3674</Id><Age>34</Age></Employee> <Name>Robin</Name><Id>3675</Id><Age>25</Age></Employee> <Name>Crow</Name><Id>3676</Id><Age>28</Age></Employee></Personnel>

9 Example 1 - DOM Create a DOM object 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 Get a list of employee elements from DOM Element docEle = dom.getDocumentElement(); NodeList nl = docEle.getElementsByTagName("Employee"); Get node value from element Get node value from elementelement.getFirstChild().getNodeValue();

10 Example 2 - SAX SAX parsing is event based modeling, it calls a tag handler whenever it encounters a tag 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 Create a SAX parser SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); sp.parse("employees.xml", this); Create Employee object when is found Create Employee object when is found if(qName.equalsIgnoreCase("Employee")) tempEmp = new Employee(); Set Employee properties when an end tag is found Set Employee properties when an end tag is found if (qName.equalsIgnoreCase("Name")) tempEmp.setName(tempVal);

12 Thank You


Download ppt "Xerces The Apache XML Project Yvonne Yao. Introduction Set of libraries that provides functionalities to parse XML documents Set of libraries that provides."

Similar presentations


Ads by Google