Re: help on DOM programming

There are actually several problems with your program. The first one is
that you simply can't use clone for that, because it only allows you to
clone nodes within a single document. What you need to use is the DOM
Level 2 method importNode instead.
Second, I don't understand why you need to get any DocumentFragment
involved in this. All you need to do is something like:

   NodeList NL = resultDoc1.getElementsByTagName("Part");

   Document resultDoc2 = DOMUtil.createDocument();
   Element root2 = resultDoc2.createElement("ROWSET");
   resultDoc2.appendChild( root2 );

  int k;
  // store the following since it can be expensive
  int l = NL.getLength();
  for (k=0;k<l;k++){

   try{
     Element row_ele = resultDoc2.createElement("ROW");
     Node imported = resultDoc2.importNode(NL.item(k), true);

     row_ele.appendChild(imported);
     root2.appendChild(row_ele);
    }
    catch (DOMException e) {
      e.printStackTrace();
    }
  }

Otherwise, if you have questions specific to XML4J, please refer to
www.alphaworks.ibm.com. This mailing list is only intended for
discussions on the _design_ of the DOM.
-- 
Arnaud  Le Hors - IBM Cupertino, XML Technology Group

Received on Thursday, 16 December 1999 20:45:36 UTC