neilg 2003/02/11 14:20:33
Modified: java/src/org/apache/xerces/dom DocumentFragmentImpl.java
Log:
when the normalize() method is invoked on a DocumentFragment object, Text/CDATA
nodes must be coalesced just as they are with Elements.
Revision Changes Path
1.11 +49 -2
xml-xerces/java/src/org/apache/xerces/dom/DocumentFragmentImpl.java
Index: DocumentFragmentImpl.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DocumentFragmentImpl.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- DocumentFragmentImpl.java 29 Jan 2002 01:15:07 -0000 1.10
+++ DocumentFragmentImpl.java 11 Feb 2003 22:20:33 -0000 1.11
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -59,6 +59,7 @@
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;
+import org.w3c.dom.Text;
/**
* DocumentFragment is a "lightweight" or "minimal" Document
@@ -140,4 +141,50 @@
return "#document-fragment";
}
+ /**
+ * Override default behavior to call normalize() on this Node's
+ * children. It is up to implementors or Node to override normalize()
+ * to take action.
+ */
+ public void normalize() {
+ // No need to normalize if already normalized.
+ if (isNormalized()) {
+ return;
+ }
+ if (needsSyncChildren()) {
+ synchronizeChildren();
+ }
+ ChildNode kid, next;
+
+ for (kid = firstChild; kid != null; kid = next) {
+ next = kid.nextSibling;
+
+ // If kid is a text node, we need to check for one of two
+ // conditions:
+ // 1) There is an adjacent text node
+ // 2) There is no adjacent text node, but kid is
+ // an empty text node.
+ if ( kid.getNodeType() == Node.TEXT_NODE )
+ {
+ // If an adjacent text node, merge it with kid
+ if ( next!=null && next.getNodeType() == Node.TEXT_NODE )
+ {
+ ((Text)kid).appendData(next.getNodeValue());
+ removeChild( next );
+ next = kid; // Don't advance; there might be another.
+ }
+ else
+ {
+ // If kid is empty, remove it
+ if ( kid.getNodeValue().length()==0 )
+ removeChild( kid );
+ }
+ }
+
+ kid.normalize();
+ }
+
+ isNormalized(true);
+ }
+
} // class DocumentFragmentImpl
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]