I finally managed to cut this down to a reasonably small test case. Cloning an imported node seems to be the problem. Possibly cloning alone causes the problem. I'm still investigating.

The following test case prints:

org.apache.xerces.jaxp.DocumentBuilderImpl
[isid: null]
[isid: null]
null

If IDs were preserved it should print

org.apache.xerces.jaxp.DocumentBuilderImpl
[isid: null]
[isid: null]
[isid: null]

i.e. the final call to getElementByID fails.

package com.elharo.xml.xinclude;

import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.InputSource;

class IDTest {

    public static void main(String[] args)  throws Exception {

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
System.out.println(parser.getClass().getName());


        InputSource input = new InputSource();

input.setSystemId("http://dev.w3.org/cvsweb/~checkout~/2001/XInclude-Test-Suite/Nist/test/ents/prtids.xml?rev=1.1&content-type=text/plain";);

        Document doc = parser.parse(input);
        doc.removeChild(doc.getDoctype());
        Element result = doc.getElementById("dup");
        System.out.println(result);

Document doc2 = doc.getImplementation().createDocument(null, "test", null);
Node imported = doc2.importNode(result, true);
doc2.getDocumentElement().appendChild(imported);
Element result2 = doc.getElementById("dup");
System.out.println(result2);


        Element data = (Element) imported.cloneNode(true);
        // doc2.getDocumentElement().replaceChild(data, imported);
        doc2.getDocumentElement().appendChild(data);
        doc2.getDocumentElement().removeChild(imported);
        result2 = doc2.getElementById("dup");
        System.out.println(result2);

    } // end main

}




-- Elliotte Rusty Harold [EMAIL PROTECTED] XML in a Nutshell 3rd Edition Just Published! http://www.cafeconleche.org/books/xian3/ http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to