2.2. Parsing an XML Document

To process an XML document, you need to parse it. A parser is a program that reads a file, confirms that the file has the correct format, breaks it up into the constituent elements, and lets a programmer access those elements. The Java library supplies two kinds of XML parsers:

• Tree parsers, such as the Document Object Model (DOM) parser, that read an XML document into a tree structure.

• Streaming parsers, such as the Simple API for XML (SAX) parser, that generate events as they read an XML document.

The DOM parser is easier to use for most purposes, and we explain it first. You may consider a streaming parser if you process very long documents whose tree structures would use up a lot of memory, or if you are ...

Get Core Java® Volume II—Advanced Features, Ninth Edition now with O’Reilly online learning.
