SAX Parsing Pattern Example

This section provides a tutorial example on how to print out the SAX parsing pattern by SAXBrowser.java with a given XML file.

Now let's use another XML file, user.xml, with more elements to show the SAX parsing pattern:

<?xml version="1.0"?>
<user status="active">
 <!-- This is not a real user. -->
 <first_name>John</first_name>
 <last_name>Smith</last_name>
</user>

Ran SAXBrowser.java with user.xml, I got:

herong> java SAXBrowser user.xml

Starting document...
e_user
a_ status=active
c__
c__

c__
c__
c__

c__
e__first_name
c___John
c__
c__

c__
e__last_name
c___Smith
c__
c__

Ending document...

The program still works. But why the parser fired so many "characters()" events? It looks like the parser didn't group the space character, line feed, and cartridge return into a single char[] and fire one "characters()" event. It fired multiple events, one per character.

Table of Contents

 About This Book

 Introduction of XML (eXtensible Markup Language)

 XML File Syntax

 XML File Browsers

 XML-JSON Document Conversion

 DOM (Document Object Model) Programming Interface

SAX (Simple API for XML) Programming Interface

 What Is SAX (Simple API for XML)

 Using SAX Implementation in JDK

 SAX Content Handler Interface

 SAXBrowser.java - SAX Interface Java Example

SAX Parsing Pattern Example

 DTD (Document Type Definition) Introduction

 Syntaxes of DTD Statements

 Validating an XML Document against the Specified DTD Document Type

 XSD (XML Schema Definition) Introduction

 Syntaxes of XSD Statements

 Validating XML Documents Against Specified XML Schemas

 XSL (Extensible Stylesheet Language) Introduction

 Java Implementation of XSLT

 XSLT (XSL Transformations) Introduction

 XPath (XML Path) Language

 XSLT Elements as Programming Statements

 Control and Generate XML Element in the Result

 PHP Extensions for XML Manipulation

 Processing XML with Python Scripts

 XML Notepad - XML Editor

 XML Tools Plugin for Notepad++

 XML Plugin Packages for Atom Editor

 XML 1.1 Changes and Parsing Examples

 Archived Tutorials

 References

 Full Version in PDF/EPUB