© Jeff Friesen 2016

JEFF FRIESEN, Java XML and JSON, 10.1007/978-1-4842-1916-4_3

3. Parsing and Creating XML Documents with DOM

Jeff Friesen

(1)Dauphin, Manitoba, Canada

SAX can parse XML documents but cannot create them. In contrast, DOM can parse and create XML documents. This chapter introduces you to DOM.

What Is DOM?

Document Object Model (DOM)is a Java API for parsing an XML document into an in-memory tree of nodes, and for creating an XML document from a node tree. After a DOM parser creates a tree, an application uses the DOM API to navigate over and extract infoset items from the tree’s nodes.

DOM has two big advantages over SAX:

  • DOM permits random access to a document’s infoset items, whereas SAX only permits serial access.

  • DOM also lets ...

Get Java XML and JSON now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.