Mantis - Resin
Viewing Issue Advanced Details
236 minor always 06-06-05 00:00 11-30-05 14:43
ferg  
 
normal  
closed 3.0.13  
3.0.13 fixed  
none    
none 3.0.14  
0000236: QDocument
RSN-259
(rep by James Howe)

I just wrote some code to replace a node inside of an DOM tree based on this article: http://access1.sun.com/techarticles/ImportingNodes/ImportingNodes.html. [^] When I stepped through the code, the resulting XML document was not what I expected to see. When using importNode with a DocumentFragment, the Resin code does not import the nodes from the document fragment. The method in question is this one in com.caucho.xml.QDocument:

  /**
   * Imports an element.
   */
  private DocumentFragment importFragment(DocumentFragment elt, boolean deep)
  {
    QDocumentFragment newFrag = new QDocumentFragment();

    newFrag._owner = this;

    if (! deep)
      return newFrag;

    for (Node node = getFirstChild();
     node != null;
     node = node.getNextSibling()) {
      newFrag.appendChild(importNode(node, true));
    }

    return newFrag;
  }

The problem, I believe is the for loop should be doing "for (Node node = elt.getFirstChild(); ..." instead of "for (Node node = getFirstChild(); ...". The way things are currently written, the importFragment code just gets elements from the owner document, not the elements from the document fragment being imported. It happens that I'm currently using Resin 3.0.8, but the source code above was taken from 3.0.12 (I haven't downloaded a later version). If it's been fixed, great. If I'm misunderstanding something, please let me know, but the code as written above doesn't make any sense if you are trying to import nodes from the document fragment into the owning document.


There are no notes attached to this issue.