This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes how to remove particular child element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "how to remove particular child element" Watch "how to remove particular child element" New topic
Author

how to remove particular child element

kesava chaitanya
Ranch Hand

Joined: Aug 15, 2001
Posts: 140
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
See the examples at JavaAlmanac.com, especially Removing a Node from a DOM Document.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: how to remove particular child element