Java Reference
In-Depth Information
names of elements. When there are two or more command-line arguments, the program should count
and report only on the elements identified by the second and subsequent command-line arguments.
2. Implement the XML Import capability in Sketcher using SAX, rather than DOM.
• WHAT YOU LEARNED IN THIS CHAPTER
TOPIC
CONCEPT
DOM
Parsers
An object of type DocumentBuilder encapsulates a DOM parser.
Creating a
DOM
Parser
You create an object encapsulating a DOM parser by using a DocumentBuilderFactory object that you
obtain by calling the static newInstance() method that is defined in the DocumentFactoryBuilder class.
Parsing
XML
You can parse an XML document by passing the document as an argument to the parse() method for a
DocumentBuilder object.
A DOM parser creates a Document object that encapsulates an entire XML document as a tree of Node ob-
jects.
Document
Objects
Analyzing
XML
Documents
The DOM API includes the Document class methods that enable you to analyze an XML document by nav-
igating through the nodes in a Document object.
Creating
XML
Documents
The DOM API includes Document class methods for creating an XML document programmatically encap-
sulated by a Document object.
Creating
XML with
a DTD
When you want to create a new XML document that includes a DTD, you use the createDocument()
method for a DOMImplementation object, rather than the newDocument() method for a DocumentBuilder
object.
Creating a
DOCTYPE
Element
You can create a DOCTYPE element by calling the createDocumentType() method for a DOMImplementa-
tion object. You can then pass the DocumentType object to the createDocument() method for the DOMIm-
plementation object to create a Document object that include the DOCTYPE element..
XSLT
A Transformer object encapsulates an XSLT transform. You create a Transformer object by first creating
a TransformerFactory object and calling its newTransformer() method. The argument to the method is
a Source object encapsulating the transform. The version with no argument creates a transformer that is
the identity transform that does nothing.
Reading
and Writ-
ing XML
Files
You can use a Transformer object that encapsulates the identity transform to write a Document object as
an XML file, or to read an XML file and create a Document object from it.
Search WWH ::




Custom Search