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

Home

Readme
Installation
Download
CVS Repository

Samples
API JavaDoc
XNI Manual
FAQs

Features
Properties

Release Info
Limitations
Report a Bug

Setting Properties
 

If you have created a DOM document builder or a SAX parser using the JAXP interfaces, you may have difficulty setting features and properties directly using those interfaces. The following instructions tell you how to set properties on document builders and SAX parsers created from the JAXP interfaces.

The DocumentBuilderFactory interface contains a setAttribute(String,Object) method which may provide a means to set features and properties on the underyling parser. However, it cannot be relied upon. Therefore, you must use the Xerces DOMParser object directly. For example:

import org.apache.xerces.parsers.DOMParser;
import org.xml.sax.SAXException;
  
DOMParser parser = new DOMParser();

String id    = "http://apache.org/xml/properties/dom/document-class-name";
Object value = "org.apache.xerces.dom.DocumentImpl";
try {
    parser.setProperty(id, value);
} 
catch (SAXException e) {
    System.err.println("could not set parser feature");
}

Using the SAXParser interface in JAXP is better because you can query the underlying XMLReader implementation directly and that interface contains methods to set and query features and properties. For example:

import javax.xml.parsers.SAXParser;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

SAXParser parser = /* created from SAXParserFactory */;
XMLReader reader = parser.getXMLReader();

String id    = "http://apache.org/xml/properties/dom/document-class-name";
Object value = "org.apache.xerces.dom.DocumentImpl";
try {
    reader.setProperty(id, value);
} 
catch (SAXException e) {
    System.err.println("could not set parser feature");
}

General Properties
 
http://xml.org/sax/properties/xml-string
 
Desc:  Get the string of characters associated with the current event. If the parser recognizes and supports this property but is not currently parsing text, it should return null.  
Type:  java.lang.String 
Access:  read-only 
Note:  This property is currently not supported because the contents of the XML string returned by this property is not well defined.  


DOM Properties
 
http://apache.org/xml/properties/dom/current-element-node
 
Desc:  The current DOM element node while parsing. 
Type:  org.w3c.dom.Element 
Access:  read-only 
Note:  This property is useful for determining the location with a DOM document when an error occurs.  

http://apache.org/xml/properties/dom/document-class-name
 
Desc:  The fully qualified class name of the DOM implementation. The implementation used must have a zero argument constructor.  
Type:  java.lang.String 
Default:  "org.apache.xerces.dom.DocumentImpl" 
Access:  read-write 
Note:  When the document class name is set to a value other than the name of the default document factory, the deferred node expansion feature does not work.  


SAX Properties
 
http://xml.org/sax/properties/declaration-handler
 
Desc:  Set the handler for DTD declarations. 
Type:  org.xml.sax.ext.DeclHandler 
Access:  read-write 

http://xml.org/sax/properties/lexical-handler
 
Desc:  Set the handler for lexical parsing events. 
Type:  org.xml.sax.ext.LexicalHandler 
Access:  read-write 

http://xml.org/sax/properties/dom-node
 
Desc:  The DOM node currently being visited, if SAX is being used as a DOM iterator. If the parser recognizes and supports this property but is not currently visiting a DOM node, it should return null.  
Type:  org.w3c.dom.Node 
Access:  (parsing) read-only; (not parsing) read-write;  
Note:  This property is only for SAX parser implementations used as DOM tree walkers. Currently, Xerces does not have this functionality.  



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