You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Ronald Bourret <rp...@hotmail.com> on 2000/06/13 17:25:45 UTC

BUG? Can't clone EntityReference with mixed content

For reasons not clear to me, I cannot clone a Node that contains an entity 
reference with mixed content. For example, attempting to clone element A in 
the following:

   <?xml version="1.0" ?>
   <!DOCTYPE a [
      <!ENTITY foo '<b/>x'>
   ]>
   <a>&foo;</a>

results in the error "DOM001 Modification not allowed". The error does not 
occur if the x is removed from the entity definition and is omitted 
altogether or placed after the entity reference.

My first guess was that the entity was not well-formed, but it meets the 
criteria that: "An internal general parsed entity is well-formed if its 
replacement text matches the production labeled content," which is defined 
as:

   [43] content ::= (element | CharData | Reference | CDSect | PI | 
Comment)*

My second guess is that the problem was related to cloning the root element, 
but this also proved to be false. Any ideas?

I am using Xerces J v. 1.1.1 and JDK 1.2.1.

-- Ron Bourret

==============================================
Code:

import org.apache.xerces.parsers.DOMParser;
import org.xml.sax.InputSource;
import org.w3c.dom.Node;

public class TestXerces3
{
   public static void main (String[] argv) throws Exception
   {
      String    xmlFilename = argv[0];
      DOMParser parser = new DOMParser();
      Node      clone, root;

      // Parse the input file and get the root.
      parser.parse(new InputSource(getFileURL(xmlFilename)));
      root = parser.getDocument().getDocumentElement();

      // Clone the root
      System.out.println("cloning...");
      clone = root.cloneNode(true);
   }

   static String getFileURL(String fileName)
   {
      File   file;
      String path, separator;

      file = new File(fileName);
      return "file:///" + file.getAbsolutePath();
   }
}

===============================================
XML Document:

<?xml version="1.0" ?>
<!DOCTYPE a [
   <!ENTITY foo '<b/>x'>
]>
<a>&foo;</a>

================================================
Output:

C:>java TestXerces3 tx3.xml
cloning...
Exception in thread "main" org.apache.xerces.dom.DOMExceptionImpl: DOM001 
Modification not allowed
        at 
org.apache.xerces.dom.ChildAndParentNode.internalInsertBefore(ChildAn
dParentNode.java:334)
        at 
org.apache.xerces.dom.ChildAndParentNode.insertBefore(ChildAndParentN
ode.java:322)
        at org.apache.xerces.dom.NodeImpl.appendChild(NodeImpl.java:214)
        at 
org.apache.xerces.dom.ChildAndParentNode.cloneNode(ChildAndParentNode
.java:185)
        at 
org.apache.xerces.dom.ChildAndParentNode.cloneNode(ChildAndParentNode
.java:185)
        at org.apache.xerces.dom.ElementImpl.cloneNode(ElementImpl.java:174)
        at TestXerces3.main(TestXerces3.java:20)

C:>
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com