aspose file tools*
The moose likes XML and Related Technologies and the fly likes problem with removing node Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "problem with removing node" Watch "problem with removing node" New topic
Author

problem with removing node

kesava chaitanya
Ranch Hand

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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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'.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
kesava chaitanya
Ranch Hand

Joined: Aug 15, 2001
Posts: 140
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;
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with removing node