[jdom-interest] Using JDOM to delete child elements
Andres March
Andres at ehealthcontracts.com
Wed May 22 13:57:45 PDT 2002
Here are the two ways IMHO I would recommend doing it:
- Use Jaxen and XPATH to locate the node and delete it
effectively you would select nodes that match event[meetingName='foo'] and remove them from their parent
- Use straight java and write a recursive method that iterates through the meetingName elements of the document. If it matches the value you care about, select its parent (an event). Then get its grandparent (a month) and remove the event from it.
-Andres
-----Original Message-----
From: Jeff Ellman [mailto:cb_elvis at hotmail.com]
Sent: Wednesday, May 22, 2002 1:12 PM
To: jdom-interest at jdom.org
Subject: [jdom-interest] Using JDOM to delete child elements
I want to use JDOM to delete an element and it's children. The element that
I want to delete will be identified by the value given to one of its child
elements.
Here's a sample of an XML document that I pretty much have to work with:
<calendar>
<!-- year attribute cannot be blank -->
<year num="">
<!-- month attribute cannot be blank -->
<month num="">
<event>
<!-- Date value cannot be blank -->
<date></date>
<meetingName></meetingName>
</event>
</month>
</year>
</calendar>
Here's another look at the XML document in application:
<calendar>
<!-- year attribute cannot be blank -->
<year num="2001">
<!-- month attribute cannot be blank -->
<month num="12">
<event>
<!-- Date value cannot be blank -->
<date>12</date>
<meetingName>Meeting 1</meetingName>
</event>
<!-- I want to delete this next event element and it's children -->
<event>
<!-- Date value cannot be blank -->
<date>12</date>
<meetingName>Remove event based on this text</meetingName>
</event>
</month>
</year>
</calendar>
How do I remove the even element based upon that event's meetingName?
Any help in this matter would be greatly appreciated. Thanks!
Sincerely,
Elvis
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
More information about the jdom-interest
mailing list