You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Gordon <Go...@cs.tcd.ie> on 2003/06/04 20:05:48 UTC
problem removing a child node from a node
hey.
I have a problem removing a child node from a node. Specifically, I'm
trying to remove an Element from a Document.
My code is:
Element elmt =doc.getElementById( id );
if( elmt == null ){
}
else{
Element discard = doc.removeChild(elmt);
}
This gives me a compile error:
found : org.w3c.dom.Node
required: org.w3c.dom.Element
discard = doc.removeChild(elmt);
^
1 error
I don't understand this because elmt is an Element and not a Node, and Node
is a superinterface of Element anyway.
Can anyone explain this? I am using Batik 1.1.1 and jdk1.3.1
Thanks.
Gordon.
RE: problem removing a child node from a node
Posted by Gordon <Go...@cs.tcd.ie>.
That works perfectly now.
Thanks for your help.
Gordon.
At 14:16 04/06/2003 -0400, you wrote:
> >>>>> "GP" == Gordon <Go...@cs.tcd.ie> writes:
>
>GP> hey. I have a problem removing a child node from a
>GP> node. Specifically, I'm trying to remove an Element from a
>GP> Document. My code is:
>
>GP> Element elmt =doc.getElementById( id ); if( elmt == null ){ }
>GP> else{ Element discard = doc.removeChild(elmt); }
>
>GP> This gives me a compile error:
>
> found : org.w3c.dom.Node
> required: org.w3c.dom.Element
> discard = doc.removeChild(elmt);
>
>GP> I don't understand this because elmt is an Element and not a Node,
>GP> and Node is a superinterface of Element anyway. Can anyone
>GP> explain this? I am using Batik 1.1.1 and jdk1.3.1 Thanks.
>
> 'discard' must be an Element. removeChild returns a Node. Also
>you don't want to call 'removeChild' on doc I think you want to call
>it on elmt's parent (unless elmt is the root element of the document).
>
> elmt.getParent().removeChild(elmt); // From memory.
RE: problem removing a child node from a node
Posted by Thomas E Deweese <th...@kodak.com>.
>>>>> "GP" == Gordon <Go...@cs.tcd.ie> writes:
GP> hey. I have a problem removing a child node from a
GP> node. Specifically, I'm trying to remove an Element from a
GP> Document. My code is:
GP> Element elmt =doc.getElementById( id ); if( elmt == null ){ }
GP> else{ Element discard = doc.removeChild(elmt); }
GP> This gives me a compile error:
found : org.w3c.dom.Node
required: org.w3c.dom.Element
discard = doc.removeChild(elmt);
GP> I don't understand this because elmt is an Element and not a Node,
GP> and Node is a superinterface of Element anyway. Can anyone
GP> explain this? I am using Batik 1.1.1 and jdk1.3.1 Thanks.
'discard' must be an Element. removeChild returns a Node. Also
you don't want to call 'removeChild' on doc I think you want to call
it on elmt's parent (unless elmt is the root element of the document).
elmt.getParent().removeChild(elmt); // From memory.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org