3

Guys:

I have a problem to remove an element from a XML file with JDOM 2.5. The problem is: under the same parent element "ApproachDat", there are multiple elements with same name as "Notes", and I only want to delete some of them based on a given criteria. I have find qualified elements that I want to delete, but I notice JDOM 2.5 only provides removeChild, which removes the first found child with given name; or removeChildren, which removes all of children elements with given name. Is there anyway to remove the exact child element that qualifies a condition?

Thanks a lot!

Sam

lxiscas
  • 141
  • 1
  • 2
  • 13
  • 1
    Try using `removeContent(Filter filter);` http://www.jdom.org/docs/apidocs/org/jdom2/filter/Filter.html if you haven't used `Filter` before – mirvine Nov 13 '14 at 21:23
  • Thank you for your kind reply! yes it is correct, and i can also use detach. – lxiscas Nov 13 '14 at 23:02

1 Answers1

1

If you have a reference to the actual element you want to remove, remember that it is polymorphically a Content object. So you can use the removeContent() method that accepts a Content reference (Javadoc).

RealSkeptic
  • 33,993
  • 7
  • 53
  • 79