[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Error when cloning DOM nodes



On Fri, 10 Nov 2000 18:28:48 +0100
Michael Keuchen <michael.keuchen@curry.de> wrote:

> Falko Braeutigam wrote:
> > Hmmm... the problem now is that ElementImpl.cloneInto() calls super.cloneInto()
> > which calls setNodeValue(), which is not allowed for Elements. I checked in a
> > work around but I'm by no means a XML expert and someone has to look into this.
> 	
> The following code seems to work (in NodeImpl.cloneInto):
> 
> 	String nodeValue = getNodeValue();
> 	if (nodeValue != null)
> 	    into.setNodeValue(nodeValue);

You can create all DOM objects without having assigned an node value.
So with this code the nodeValue member would be null in this case and
you couldn't clone this node in the correct way, because the null value
would not be adopted. I would prefer a solution that either tests the
thrown exception or checks the current node type.

> So the hack can be removed:
>         try {
>             into.setNodeValue( _nodeValue );
>         }
>         catch (DOMExceptionImpl e) {
>             if (e.code != DOMException.NO_DATA_ALLOWED_ERR) {
>                 throw e;
>             }
>         }
> 
> Michael Keuchen

Regards,
Lars
--
___________________________________________________________________
Lars Martin                                 mailto:lars@smb-tec.com
SMB GmbH                                     http://www.smb-tec.com