On further investigation, it definitely the cloning that's causing the loss of IDness, not the importing. I can parse a document, search it for an element with an ID, find i; then replace that element with its own clone, search it again, and come up empty. Here's the code:

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);

doc.getDocumentElement().replaceChild(result.cloneNode(true), result);
result = doc.getElementById("dup");
System.out.println(result);


    } // end main

}

Note that I do not remove the document type declaration and that the clone has the same attributes with the same name as the original, so if it's reading IDness from the DTD it should still be an ID.


-- 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