Lesson 7
XML Parser Conclusion
In this module we have explained the operation of an XML parser and provided a working
classification of existing XML parsers. We have also introduced and explained two models for parsing XML documents: the DOM and SAX models.
Understanding the operation and models of XML parsers is critical to making the correct decisions as to which parser to use the most effective
ways of using one.
Learning objectives
Having completed this module, you should now be able to:
Explain how an XML parser works:
The XML parser works between the client application and the XML document and its purpose is to validate the document which is passing through it.
It is mainly designed using the XML document structure and it has programs to read the XML document. The XML parsing is working with all browsers to read and write it and it has a simple API. XML Parser provides a way to access or modify data in an XML document. Java provides multiple options to parse XML documents. Following are the various types of parsers which are commonly used to parse XML documents.
- Differentiate between the types of parsers and how they are used
- Outline the steps for using an XML parser
- Explain the Document Object Model (DOM) for parsing XML documents.
The DOM Parser parses an XML document by loading the complete contents of the document and creating its complete hierarchical tree in memory
- Explain the Simple API for XML (SAX) model for parsing XML documents.
The SAX Parser parses an XML document using event-based triggers and does not load the complete document into the memory.
StAX API
StAX is a Java-based API to parse XML document in a similar way as SAX parser does. But there are two major difference between the two APIs.
StAX is a PULL API, whereas SAX is a PUSH API. It means in case of StAX parser, a client application needs to ask the StAX parser to get information from XML whenever it needs. In the case of the SAX parser, a client application is required to get information when the SAX parser notifies the client application that information is available. The StAX API can read as well as write XML documents. When using the SAX API, the XML file can only be read.
Additional XML Parsers
- JDOM Parser: Parses an XML document in a similar fashion to DOM parser but in an easier way.
- XPath Parser: Parses an XML document based on expression and is used extensively in conjunction with XSLT.
- DOM4J Parser: A Java Library used to parse XML, XPath, and XSLT using the Java Collections Framework. It provides support for DOM, SAX, and JAXP.
Glossary terms
This module introduced the following terms:
- APIs
- Document handler
- Document Object Model (DOM)
- Parser constructor
- Parser object instance
- Simple API forXML (SAX)
In the next module, you will learn about Xlink, Xpointer, and metadata.
XML Parser - Quiz
Click the Quiz link below to check your understanding of XML parsers.
XML Parser - Quiz