W3C home > Mailing lists > Public > www-dom@w3.org > October to December 1999

help on DOM programming

From: Jian Chen <jchen@smartcad4.me.wisc.edu>
Date: Thu, 16 Dec 1999 17:30:57 -0600
Message-ID: <38597631.E93D0627@smartcad.me.wisc.edu>
To: www-dom@w3.org
Dear Sir,

I have a  problem on DOM programming, If you have time,please read my

I want to copy a fragment of document to another document. The fragment

<Part num="1">
      <Specifications Parameter1="123" Parameter2="456"

  <Part num="2">
      <Specifications Parameter1="123" Parameter2="456"

I use the following JAVA code:

   NodeList NL = resultDoc1.getElementsByTagName("Part");
   DocumentFragment DFrag1 = resultDoc1.createDocumentFragment();

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

  int k;
  for (k=0;k<NL.getLength();k++){

     Element row_ele = resultDoc2.createElement("ROW");

     //the error line 1
     DFrag1 = (DocumentFragment)NL.item(k);
     DFrag2 = (DocumentFragment)DFrag1.cloneNode(true);

    //the error line 2
    catch (DOMException e) {

But I got the java.lang.ClassCastException on the line which I indicate
"the error line 1" above.

If I just use Node type, instead of DocumentFragment, then I got the
com.ibm.xml.dom.DOMExceptionImpl on the line which I indicate "the error

line 2" above.

Would you give me some suggestion?
Received on Thursday, 16 December 1999 18:27:52 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:06 UTC