Using Xpath delete a single node

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<?xml version="1.0"?><br/>
<filter><br/>
<textfilter><br/>
<text category="1 <br/>
<string>xxx</string><br/>
<string>ertertert</string><br/>
<string>ertert</string><br/>
</text><br/>
</textfilter><br/>
<numberfilter><br/>
<text nubcategory="1 <br/>
<string>11111111111</string><br/>
<string>2222222222</string> ------ i need to delete this node<br/>
<string>3333333333</string><br/>
</text><br/>
</numberfilter><br/>
</filter><br/>
<br/>
i need to delete the <string>2222222222</string>
node <br/>


<pre style="font-family:Consolas; font-size:13px; color:black; background:none repeat scroll 0% 0% white <span style="color:#2b91af XmlDocument xmlDoc = <span style="color:blue new <span style="color:#2b91af XmlDocument();
xmlDoc.Load(<span style="color:#a31515 @"D:bijeshWorkingRequestRouterMoobleHandlerXML" + fileName);
<span style="color:blue string path = <span style="color:#2b91af String.Format(<span style="color:#a31515 "//numberfilter//text[string={0}]//string", " 2312112124 ");
<span style="color:#2b91af XmlNode newXMLNodes = xmlDoc.SelectSingleNode(path);
<span style="color:green newXMLNodes.ParentNode.RemoveChild(newXMLNodes);
xmlDoc.Save(<span style="color:#a31515 @"D:bijeshWorkingRequestRouterMoobleHandlerXML" + fileName);
<br/><br/>in this case if i run this code <string>2312112124</string> will not be deleted, but it delete only the first node element<br/> <string>11111111111</string> <br/><br/><br/>[/code]<hr class="sig Good Judgment Comes From Experience, And Experience Comes From Bad Judgment

View the full article
 
Back
Top