mrglavas 2004/09/27 20:59:17
Modified: java/docs properties.xml features.xml
Log:
Update features and properties docs. We should be
showing examples which use JAXP rather than ones
which use org.apache.xerces.parsers.DOMParser
directly.
Revision Changes Path
1.17 +17 -16 xml-xerces/java/docs/properties.xml
Index: properties.xml
===================================================================
RCS file: /home/cvs/xml-xerces/java/docs/properties.xml,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- properties.xml 14 Jul 2004 04:42:34 -0000 1.16
+++ properties.xml 28 Sep 2004 03:59:17 -0000 1.17
@@ -19,36 +19,37 @@
<desc name='Setting Properties'>
<p>
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 JAXP interfaces, the following instructions tell you how to
+ set properties on document builders and SAX parsers created from
+ the JAXP interfaces.
</p>
<p>
The DocumentBuilderFactory interface contains a
<code>setAttribute(String,Object)</code> method which <em>may</em>
- 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:
+ provide a means to set properties on the underyling parser. When
+ using Xerces, you can set the value of a property with this method.
+ For example:
</p>
- <source>import org.apache.xerces.parsers.DOMParser;
-import org.xml.sax.SAXException;
+ <source>import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
-DOMParser parser = new DOMParser();
+DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
String id = "http://apache.org/xml/properties/dom/document-class-name";
Object value = "org.apache.xerces.dom.DocumentImpl";
try {
- parser.setProperty(id, value);
+ dbf.setAttribute(id, value);
}
-catch (SAXException e) {
+catch (IllegalArgumentException e) {
System.err.println("could not set parser property");
}</source>
<p>
- 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:
+ The SAXParser interface contains a
+ <code>setProperty(String,Object)</code> method which can be used
+ to set properties on the underlying implementation of <code>XMLReader</code>.
+ You can also retrieve the underlying <code>XMLReader</code> from the
+ SAXParser allowing you to set and query properties on it directly.
+ For example:
</p>
<source>import javax.xml.parsers.SAXParser;
import org.xml.sax.SAXException;
1.41 +19 -17 xml-xerces/java/docs/features.xml
Index: features.xml
===================================================================
RCS file: /home/cvs/xml-xerces/java/docs/features.xml,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- features.xml 14 Jul 2004 04:42:34 -0000 1.40
+++ features.xml 28 Sep 2004 03:59:17 -0000 1.41
@@ -19,34 +19,36 @@
<desc name='Setting Features'>
<p>
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 features on document builders
- and SAX parsers created from the JAXP interfaces.
+ the JAXP interfaces, the following instructions tell you how to
+ set features on document builders and SAX parsers created from
+ the JAXP interfaces.
</p>
<p>
The DocumentBuilderFactory interface contains a
<code>setAttribute(String,Object)</code> method which <em>may</em>
- 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:
+ provide a means to set features on the underyling parser. When using
+ Xerces, to set a feature you specify an instance of
+ <code>java.lang.Boolean</code> as the value of the attribute.
+ For example:
</p>
- <source>import org.apache.xerces.parsers.DOMParser;
-import org.xml.sax.SAXException;
+ <source>import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
-DOMParser parser = new DOMParser();
+DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
- parser.setFeature("http://apache.org/xml/features/allow-java-encodings",
- true);
+ dbf.setAttribute("http://apache.org/xml/features/allow-java-encodings",
+ Boolean.TRUE);
}
-catch (SAXException e) {
+catch (IllegalArgumentException e) {
System.err.println("could not set parser feature");
}</source>
<p>
- 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:
+ The SAXParserFactory interface contains a
+ <code>setFeature(String,boolean)</code> method which can be used
+ to set features on the underlying implementation of <code>XMLReader</code>.
+ Once you create the SAXParser you can retrieve the underlying
+ <code>XMLReader</code> allowing you to set and query features on it directly.
+ For example:
</p>
<source>import javax.xml.parsers.SAXParser;
import org.xml.sax.SAXException;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]