http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Home

Readme
Installation
Download
CVS Repository

Samples
API JavaDoc
FAQs

Features
Properties

XNI Manual
XML Schema
DOM
Limitations

Release Info
Report a Bug

Overview
 

This page documents the various Document Object Model (DOM) samples included with Xerces. Besides being useful programs, they can be used as DOM programming examples to learn how to program using the DOM API.

Basic DOM samples:

Most of the DOM parser samples have a command line option that allows the user to specify a different DOM parser to use. In order to supply another DOM parser besides the default Xerces DOMParser, a DOM parser wrapper class must be written. This class must implement the dom.ParserWrapper interface.

Note: JAXP could be used instead of the special DOM parser wrapper class. However, that feature is not implemented at this time. Using JAXP would require the user to specify the -Djavax.xml.parsers.DocumentBuilderFactory=... option to the virtual machine in order to use a different document builder factory.

Sample dom.Counter
 

A sample DOM counter. This sample program illustrates how to traverse a DOM tree in order to get information about the document. The output of this program shows the time and count of elements, attributes, ignorable whitespaces, and characters appearing in the document. Three times are shown: the parse time, the first traversal of the document, and the second traversal of the tree.

This class is useful as a "poor-man's" performance tester to compare the speed and accuracy of various DOM parsers. However, it is important to note that the first parse time of a parser will include both VM class load time and parser initialization that would not be present in subsequent parses with the same file.

Note: The results produced by this program should never be accepted as true performance measurements.
usage
 
java dom.Counter (options) uri ...

options
 
Option  Description 
-p name  Select parser wrapper by name. 
-x number  Select number of repetitions. 
-n | -N  Turn on/off namespace processing. 
-np | -NP  Turn on/off namespace prefixes.
NOTE: Requires use of -n.  
-v | -V  Turn on/off validation. 
-s | -S  Turn on/off Schema validation support.
NOTE: Not supported by all parsers.  
-f | -F  Turn on/off Schema full checking.
NOTE: Requires use of -s and not supported by all parsers.  
-h  Display help screen. 


Sample dom.DOMAddLines
 

A sample of Adding lines to the DOM Node. This sample program illustrates:

  • How to override methods from DocumentHandler ( XMLDocumentHandler)
  • How to turn off ignorable white spaces by overriding ignorableWhiteSpace
  • How to use the SAX Locator to return row position (line number of DOM element)
  • How to attach user defined Objects to Nodes using method setUserData
usage
 
java dom.DOMAddLines (options) uri ...

options
 
Option  Description 
-h  Display help screen. 
-i  Don't print ignorable white spaces. 


Sample dom.GetElementsByTagName
 

A sample DOM filter. This sample program illustrates how to use the Document#getElementsByTagName() method to quickly and easily locate elements by name.

usage
 
java dom.GetElementsByTagName (options) uri ...

options
 
Option  Description 
-p name  Select parser wrapper by name. 
-e name  Specify element name for search. 
-a name  Specify attribute name for specified elements. 
-n | -N  Turn on/off namespace processing. 
-v | -V  Turn on/off validation. 
-s | -S  Turn on/off Schema validation support.
NOTE: Not supported by all parsers.  
-h  Display help screen. 


Sample dom.Writer
 

A sample DOM writer. This sample program illustrates how to traverse a DOM tree in order to print a document that is parsed.

usage
 
java dom.Writer (options) uri ...

options
 
-p name  Select parser wrapper by name. 
-n | -N  Turn on/off namespace processing. 
-v | -V  Turn on/off validation. 
-s | -S  Turn on/off Schema validation support.
NOTE: Not supported by all parsers.  
-c | -C  Turn on/off Canonical XML output.
NOTE: This is not W3C canonical output.  
-h  Display help screen. 


Sample dom.ASBuilder
 

This sample program illustrates how to preparse xml schema documents and how to validate instance documents against preparsed schema grammars.

Note:The Abstract Schema module implementation is deprecated. You should use Xerces Grammar cashing functionality to pre-parse schemas.
usage
 
java dom.ASBuilder [-f|-F] -a uri ... [-i uri ...]

options
 
-f | -F  Turn on/off schema full checking. 
-a uri ...  Provide a list of schema documents. 
-i uri ...  Provide a list of instance documents to validate. 


Sample dom.DOM3
 

This sample program illustrates how to use the DOM Level 3 API.

Note:This sample is not included in the default Xerces distribution. The sample uses the DOM Level 3 interfaces and will not complile with the default Xerces build.

To access this sample you need to check out the code from CVS and build Xerces with jars-dom3 build target (for more information, please refer to How do I access the DOM Level 3 functionality?.

usage
 
java dom.DOM3 uri



Copyright © 1999-2002 The Apache Software Foundation. All Rights Reserved.