Java Reference
In-Depth Information
Creating and Modifying XML
Documents
In this chapter we will concentrate on understanding what we can do with the DOM API. As we
outlined in the previous chapter, DOM uses a mechanism that is completely different to SAX. As well
as providing an alternative mechanism for parsing XML documents, DOM also adds the capability for
you to modify them and create new ones.
In this chapter you will learn:
What a document object model is
How you create a DOM parser
How you access the contents of a document using DOM
How you create and update a new XML document
How to modify Sketcher to read and write sketches as XML documents
The Document Object Model (DOM)
As we saw in the previous chapter, a DOM parser presents you with an object encapsulating the entire
XML structure. You can then call methods belonging to this object to navigate through the document
tree and process the elements and attributes in the document in whatever way you want. This is quite
different to SAX as we have already noted, but nonetheless there is quite a close relationship between
DOM and SAX.
The mechanism for getting access to a DOM parser is very similar to what we used to obtain a SAX
parser. You start with a factory object that you obtain like this:
Search WWH ::




Custom Search