sboag 00/12/19 16:04:06
Modified: java/src/org/apache/xml/utils DOMBuilder.java
Log:
Suppress addition of whitespace when outside a document
element, to avoid DOM006 Hierarchy request errors.
Revision Changes Path
1.3 +22 -0 xml-xalan/java/src/org/apache/xml/utils/DOMBuilder.java
Index: DOMBuilder.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/DOMBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DOMBuilder.java 2000/11/30 20:13:59 1.2
+++ DOMBuilder.java 2000/12/20 00:04:06 1.3
@@ -399,6 +399,9 @@
*/
public void characters(char ch[], int start, int length) throws
org.xml.sax.SAXException
{
+ if(isOutsideDocElem()
+ && org.apache.xml.utils.XMLCharacterRecognizer.isWhiteSpace(ch,
start, length))
+ return; // avoid DOM006 Hierarchy request error
if (m_inCData)
{
@@ -426,7 +429,11 @@
public void charactersRaw(char ch[], int start, int length)
throws org.xml.sax.SAXException
{
+ if(isOutsideDocElem()
+ && org.apache.xml.utils.XMLCharacterRecognizer.isWhiteSpace(ch,
start, length))
+ return; // avoid DOM006 Hierarchy request error
+
String s = new String(ch, start, length);
append(m_doc.createProcessingInstruction("xslt-next-is-raw",
@@ -498,11 +505,23 @@
public void ignorableWhitespace(char ch[], int start, int length)
throws org.xml.sax.SAXException
{
+ if(isOutsideDocElem())
+ return; // avoid DOM006 Hierarchy request error
String s = new String(ch, start, length);
append(m_doc.createTextNode(s));
}
+
+ /**
+ * Tell if the current node is outside the document element.
+ *
+ * @return true if the current node is outside the document element.
+ */
+ private boolean isOutsideDocElem()
+ {
+ return m_elemStack.size() == 0 && (null == m_currentNode ||
m_currentNode.getNodeType() == Node.DOCUMENT_NODE);
+ }
/**
* Receive notification of a processing instruction.
@@ -589,6 +608,9 @@
*/
public void cdata(char ch[], int start, int length) throws
org.xml.sax.SAXException
{
+ if(isOutsideDocElem()
+ && org.apache.xml.utils.XMLCharacterRecognizer.isWhiteSpace(ch,
start, length))
+ return; // avoid DOM006 Hierarchy request error
String s = new String(ch, start, length);