• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

problem with removing node

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

i have written program to remove node of indianplayer with attribute value =9;but its going to the if statement but unable to remove the particular node;whats wrong with the code;i am using DOM parser;

NodeList indianplayers = root.getElementsByTagName("IndianPlayer");


for(int i=0;i<indianplayers.getLength();i++)
{

Element el=(Element) indianplayers.item(i);


String playerid1 =el.getAttribute("PlayerId");
int playeridd=Integer.parseInt(playerid1);
if(playeridd == Integer.parseInt(request.getParameter("playerid")))
{
root.removeChild(indianplayers.item(i));
}

}

<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>
<IndianPlayer PlayerId="10">

<Name>Balaji</Name>

<Age>26</Age>

</IndianPlayer>

</India>

bye

chaitanya
[ June 18, 2004: Message edited by: kesava chaitanya ]
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you figure that the node is not being removed? If the Node you pass to root.removeChild(childNodeToRemove) is not a child of the context Node, you'd get a DOMException saying that 'childNodeToRemove' is not a child of 'root'.
 
kesava chaitanya
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lasse Koskela:
How do you figure that the node is not being removed? If the Node you pass to root.removeChild(childNodeToRemove) is not a child of the context Node, you'd get a DOMException saying that 'childNodeToRemove' is not a child of 'root'.



i solved my problem;i didnt append to xml document;
 
Right! We're on it! Let's get to work tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic