• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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
 
pie. tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic