• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Remove Element from DOM using XPath

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have below XML structure
<Details>
<Detail>
<Name>A</Name>
<Age>11</Age>
</Detail>
<Detail>
<Name>B</Name>
<Age>12</Age>
</Detail>
</Details>

Structure may have many <Detail> elements.

Now I want to remove all <Detail> elements which falls under a specific criteria (for ex: Name value ='A' or Age>15 etc.

Do we have any API which allows me do this. Some thing like removeElement(document, XPath).

Anirudha
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to XML...
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anirudha,

If you want to delete a node you should be at a parent level(parent node) to do it :

Ex:

if according to your condition "nd" is the node to be deleted then use the statement

nd.getParentNode().removeChild(nd);

Where nd is a "Node"

Regards
Balaji Pattabhiraman
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic