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 Travis Rein <tr...@radiks.net> on 2000/06/13 03:11:16 UTC

Bug

Using:
Xerces J 1.1.1
IBM JDK 1.1.7p

Description:
Document.cloneNode(true) doesn't work if the first node in the document being copied is not first accessed. The following code illustrates this. Leave the two lines commented and it breaks. Uncomment them and it works fine.

===============================
import java.io.*;
import java.util.*;
import org.apache.xerces.dom.*;
import org.apache.xerces.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;

public class CloneTest {
  static String fileStr = "<test><node1><node2/></node1></test>";
  
  public static void main(String args[]) {
    Node child = null;
    
    try {
      DOMParser parser = new DOMParser();
      StringReader sr = new StringReader(fileStr);
      parser.parse(new InputSource(sr));
      Document document = parser.getDocument();
      
      /**** Uncomment either of these lines to get it to work ****/
      /* child = document.getFirstChild(); */
      /* child = document.getDocumentElement(); */
      
      Document copy = (Document) document.cloneNode(true);
      System.out.println("Name: " + copy.getNodeName());
      if (copy.getNodeType() == Node.DOCUMENT_NODE) {
        System.out.println("Is document");
      }
      
      System.out.println("Testing copy of document");
      child = copy.getFirstChild();
      if (child != null) {
        System.out.println("First child name: " + child.getNodeName());
      } else {
        System.out.println("First child null");
      }
      child = copy.getDocumentElement();
      if (child != null) {
        System.out.println("Document element name: " + child.getNodeName());
      } else {
        System.out.println("Document element null");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    
    System.exit(0);
  }
}

Re: Bug

Posted by Daniel Barclay <Da...@digitalfocus.com>.
> Travis Rein wrote:
> ...
> <FONT size=2>...


If you're going to post HTML, post in the default HTML font 
size.  Don't shrink it from the default, especially not by 
_two_ sizes.



-- 
Daniel Barclay
Digital Focus
Daniel.Barclay@digitalfocus.com