Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to remove particular child element

 
kesava chaitanya
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i have one xml document like this;how to remove particular element ;i want to remove say playerid = 9;

and also i want to update the particular element, IndianPlayer(child nodes(name,age)) say playerid = 5 with name=agarkar and age=27;
<India>
<IndianPlayer PlayerId="1">
<Name>Sachin</Name>
<Age>31</Age>
</IndianPlayer>
<IndianPlayer PlayerId="2">
<Name>Saurav</Name>
<Age>32</Age>
</IndianPlayer>
<IndianPlayer PlayerId="3">
<Name>Yuvraj</Name>
<Age>22</Age>
</IndianPlayer>
<IndianPlayer PlayerId="4">
<Name>Dravid</Name>
<Age>32</Age>
</IndianPlayer>
<IndianPlayer PlayerId="5">
<Name>Kumble</Name>
<Age>34</Age>
</IndianPlayer>
<IndianPlayer PlayerId="6">
<Name>Sehwag</Name>
<Age>24</Age>
</IndianPlayer>
<IndianPlayer PlayerId="7">
<Name>Laxman</Name>
<Age>32</Age>
</IndianPlayer>
<IndianPlayer PlayerId="8">
<Name>parthiv</Name>
<Age>18</Age>
</IndianPlayer>
<IndianPlayer PlayerId="9">

<Name>Zaheerkhan</Name>

<Age>26</Age>

</IndianPlayer>

</India>


bye
chaitanya
[ June 17, 2004: Message edited by: kesava chaitanya ]
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the examples at JavaAlmanac.com, especially Removing a Node from a DOM Document.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, for updating elements in a DOM tree, you simply use the methods provided for the org.w3c.dom.Node interface that all your element objects implement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic