You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by an...@locus.apache.org on 2000/01/08 00:32:29 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/parsers DOMParser.java
andyc 00/01/07 15:32:29
Modified: java/docs features.xml
java/src/org/apache/xerces/parsers DOMParser.java
Log:
Added feature so that user can decide whether or not ignorable
whitespace text nodes appear in the DOM tree. By default, the
text nodes are there and, thus, there appears to be no change
from current behavior.
Revision Changes Path
1.3 +13 -0 xml-xerces/java/docs/features.xml
Index: features.xml
===================================================================
RCS file: /home/cvs/xml-xerces/java/docs/features.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- features.xml 1999/12/20 17:41:03 1.2
+++ features.xml 2000/01/07 23:32:28 1.3
@@ -134,6 +134,19 @@
the DOM tree. The document will always contain the entity reference
child nodes.</td></tr>
</table>
+ <p>http://apache.org/xml/features/dom/include-ignorable-whitespace</p>
+ <table>
+ <tr><th>true</th><td>Include ignorable whitespace text nodes in the DOM tree.</td></tr>
+ <tr><th>false</th><td>Do not include ignorable whitespace text nodes in the DOM tree.</td></tr>
+ <tr><th>Default</th><td>true</td></tr>
+ <tr><th>Note</th><td>The only way that the parser can determine if text
+ is ignorable is by reading the associated grammar
+ and having a content model for the document. When
+ ignorable whitespace text nodes are included in
+ the DOM tree, they will be flagged as ignorable.
+ The ignorable flag can be queried by calling the
+ TextImpl#isIgnorableWhitespace():boolean method.</td></tr>
+ </table>
</s2>
<s2 title="SAX Features">
<p>http://xml.org/sax/features/use-locator</p>
1.4 +77 -0 xml-xerces/java/src/org/apache/xerces/parsers/DOMParser.java
Index: DOMParser.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/DOMParser.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DOMParser.java 2000/01/05 01:39:23 1.3
+++ DOMParser.java 2000/01/07 23:32:28 1.4
@@ -133,6 +133,7 @@
// Xerces features
"http://apache.org/xml/features/dom/defer-node-expansion",
"http://apache.org/xml/features/dom/create-entity-ref-nodes",
+ "http://apache.org/xml/features/dom/include-ignorable-whitespace",
// Experimental features
"http://apache.org/xml/features/domx/grammar-access",
};
@@ -184,6 +185,7 @@
private String fDocumentClassName;
private boolean fDeferNodeExpansion;
private boolean fCreateEntityReferenceNodes;
+ private boolean fIncludeIgnorableWhitespace;
// built-in entities
@@ -230,6 +232,7 @@
setDocumentClassName(DEFAULT_DOCUMENT_CLASS_NAME);
setCreateEntityReferenceNodes(true);
setDeferNodeExpansion(true);
+ setIncludeIgnorableWhitespace(true);
} catch (SAXException e) {
throw new RuntimeException("fatal error constructing DOMParser");
}
@@ -429,6 +432,39 @@
return fCreateEntityReferenceNodes;
}
+ /**
+ * This feature determines whether text nodes that can be
+ * considered "ignorable whitespace" are included in the DOM
+ * tree.
+ * <p>
+ * Note: The only way that the parser can determine if text
+ * is ignorable is by reading the associated grammar
+ * and having a content model for the document. When
+ * ignorable whitespace text nodes *are* included in
+ * the DOM tree, they will be flagged as ignorable.
+ * The ignorable flag can be queried by calling the
+ * TextImpl#isIgnorableWhitespace():boolean method.
+ *
+ * @param include True to include ignorable whitespace text nodes;
+ * false to not include ignorable whitespace text
+ * nodes.
+ *
+ * @see #getIncludeIgnorableWhitespace
+ */
+ public void setIncludeIgnorableWhitespace(boolean include) throws SAXException {
+ fIncludeIgnorableWhitespace = include;
+ }
+
+ /**
+ * Returns true if ignorable whitespace text nodes are included
+ * in the DOM tree.
+ *
+ * @see #setIncludeIgnorableWhitespace
+ */
+ public boolean getIncludeIgnorableWhitespace() throws SAXException {
+ return fIncludeIgnorableWhitespace;
+ }
+
// properties
/**
@@ -576,6 +612,24 @@
}
//
+ // http://apache.org/xml/features/dom/include-ignorable-whitespace
+ // This feature determines whether text nodes that can be
+ // considered "ignorable whitespace" are included in the DOM
+ // tree.
+ // Note: The only way that the parser can determine if text
+ // is ignorable is by reading the associated grammar
+ // and having a content model for the document. When
+ // ignorable whitespace text nodes *are* included in
+ // the DOM tree, they will be flagged as ignorable.
+ // The ignorable flag can be queried by calling the
+ // TextImpl#isIgnorableWhitespace():boolean method.
+ //
+ if (feature.equals("dom/include-ignorable-whitespace")) {
+ setIncludeIgnorableWhitespace(state);
+ return;
+ }
+
+ //
// Experimental features
//
@@ -663,6 +717,23 @@
}
//
+ // http://apache.org/xml/features/dom/include-ignorable-whitespace
+ // This feature determines whether text nodes that can be
+ // considered "ignorable whitespace" are included in the DOM
+ // tree.
+ // Note: The only way that the parser can determine if text
+ // is ignorable is by reading the associated grammar
+ // and having a content model for the document. When
+ // ignorable whitespace text nodes *are* included in
+ // the DOM tree, they will be flagged as ignorable.
+ // The ignorable flag can be queried by calling the
+ // TextImpl#isIgnorableWhitespace():boolean method.
+ //
+ if (feature.equals("dom/include-ignorable-whitespace")) {
+ return getIncludeIgnorableWhitespace();
+ }
+
+ //
// Experimental features
//
@@ -1107,6 +1178,12 @@
/** Ignorable whitespace. */
public void ignorableWhitespace(int dataIndex) throws Exception {
+
+ // ignore the whitespace
+ if (!fIncludeIgnorableWhitespace) {
+ fStringPool.orphanString(dataIndex);
+ return;
+ }
// deferred node expansion
if (fDeferredDocumentImpl != null) {