xerces-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Binna" <r.bi...@hs-prior.tsn.at>
Subject Re: HTMLDocumentImpl and clone
Date Tue, 24 Aug 2004 11:06:28 GMT
Hi.

Thanks for your reply.
I solved the Problem by changing back to the default DocumentImpl but
isnt't your code almost the same as it is in HTMLDocumentImpl.
This is the code I copied from the xerces-2.6.3 source from
HTMLDocumentImpl.java:

public Node cloneNode( boolean deep )
    {
        HTMLDocumentImpl    clone;
        NodeImpl            node;

        clone = new HTMLDocumentImpl();
        if ( deep ) {
            node = (NodeImpl) getFirstChild();
            while ( node != null ) {
                clone.appendChild( clone.importNode( node, true ) );
                node = (NodeImpl) node.getNextSibling();
            }
        }
        return clone;
    }

Regards,
        Robert

----- Original Message ----- 
From: "Christopher Ebert" <CEbert@pocketthis.com>
To: <xerces-j-user@xml.apache.org>
Sent: Monday, August 23, 2004 10:38 PM
Subject: RE: HTMLDocumentImpl and clone



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:r.binna@hs-prior.tsn.at]
Sent: Sunday, August 22, 2004 15:34
To: xerces-j-user@xml.apache.org
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: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Mime
View raw message