Hi,
        Haven't seen a reply on the list yet, so the short answer is
Xerces does not support 'clone' on parts of the DOM. What you can do
instead is import the nodes you want into another document. The code
looks something like this:
                Document nodeDoc = parentNode.getOwnerDocument();
                if (childNodeToImport instanceof Document) {
                        childNodeToImport = ((Document)
childNodeToImport).getDocumentElement();
                }
                Node importedDoc = nodeDoc.importNode(childNodeToImport,
true);
                parentNode.appendChild(importedDoc);

Where:
 parentNode: is the node in your new document to which you want to
attach the DOM fragment. If you just want to put it in a fresh document,
you don't need to get the 'owner' of the document (you'll get exceptions
if you do...)
 childNodeToImport: the DOM fragment you want to duplicate. If it is a
document, you need to get the 'document element' of the document.

The remaining code does the import and attaches the resulting DOM
structure.


I think there's a FAQ about this -- if not, maybe there should be...


Chris


-----Original Message-----
From: Robert Binna [mailto:[EMAIL PROTECTED] 
Sent: Sunday, August 22, 2004 15:34
To: [EMAIL PROTECTED]
Subject: HTMLDocumentImpl and clone

Hi

I had a code that worked fine with the library openxml. Now I wanted to
changed to Xerces. I parsed the XHTML-File and all worked fine, but when
I wanted to clone the Document I get the following Exception:

org.w3c.dom.DOMException: NOT_SUPPORTED_ERR: The implementation does not
support the requested type of object or operation.
at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown Source) at
org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown Source) at
org.apache.html.dom.HTMLDocumentImpl.cloneNode(Unknown Source)

This was the code that was the reason for this exception:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setAttribute("http://apache.org/xml/properties/dom/document-clas
s-na
me","org.apache.html.dom.HTMLDocumentImpl");
DocumentBuilder builder = factory.newDocumentBuilder(); domDocument =
builder.parse(filename); HTMLDocument doc = (HTMLDocument)
domDocument.cloneNode(true);

Is this my fault or is it a bug in Xerces?

Regards,
        Robert


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


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

Reply via email to