[jdom-interest] How to remove a child by specifying the value of an attribute?

Benjamin Kopic benjamin.kopic at pancontext.com
Sun Aug 11 10:21:03 PDT 2002

Have a look at Jaxen (http://www.jaxen.org/), which is compatible with JDOM.
You can specify an XPath expression to filter on and then detach the element
from the tree.

You might use something like this:

Document myDoc = saxBuilder.build();
XPath xPath = new JDOMXPath("*/[value1='17']");
Element bbbToRemove = xPath.selectSingleNode(myDoc);

I hope this helps, but make sure that you read the documentation first.


----- Original Message -----
From: "Supriyo Chatterjea" <supriyo_chatterjea at yahoo.com.sg>
To: <jdom-interest at jdom.org>
Sent: Sunday, August 11, 2002 5:43 PM
Subject: [jdom-interest] How to remove a child by specifying the value of an

> Hi,
> I need to remove a child with a certain specific
> attribute value, e.g.
> I've got the following file:
> <aaa>
>   <bbb value1="12" value2="12" value3="12">
>     <ccc time="9"/>
>   </bbb>
>   <bbb value1="17"  value2="23" value3="57">
>     <ccc time="4"/>
>   </bbb>
>   <bbb value1="24"  value2="200" value3="94">
>     <ccc time="2"/>
>   </bbb>
> </aaa>
> Now suppose I want to remove the child <bbb> of <aaa>
> that has an attribute value1=17. So in this case that
> would mean removing the 2nd element. How do I remove
> an element by specifying not only it's name but also
> the value of a certain attribute?
> removechild(...) only deletes then first child with
> the specified name and namespace.
> Would appreciate a short example...
> Thanks for the help!
> Supriyo
> __________________________________________________
> Do You Yahoo!?
> Win a DV camera, join our "30 Seconds of Fame" contest
> http://sg.movies.yahoo.com
> _______________________________________________
> To control your jdom-interest membership:

More information about the jdom-interest mailing list