This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with removing node

 
kesava chaitanya
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • 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 ]
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • 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
  • 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;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic