Hi Guys,
I have an xmlfile
<data>
<website name="abc" url="www.abc.com" enable="Yes">
<website name="abc1" url="www.abc1.com" enable="Yes">
</data>
I want to write code using System.XML namespace to delete node name="abc".
Please help.. I will highly appreciate your help...
Thanks

URGENT :: XML DeleteNode help needed!!!!!!
hiling
Here is my C# code... Although I am getting an error..
"Object reference not set to an instance of an object."
XmlDataDocument xmlDoc = new XmlDataDocument();xmlDoc.Load(dataFile);
//XmlNode node = xmlDoc.GetElementsByTagName("website");
foreach(XmlNode node in xmlDoc.GetElementsByTagName("website")){
//if (node) //{node.RemoveChild(node.SelectSingleNode(
"/website[@name='" + this.cboURLName.Text + "']")); Console.WriteLine("/data/website[name='" + this.cboURLName.Text + "']"); break; //}}
Vlad Dogaru
HERE IS THE ANOTHER TRY I DID. THE CODE BELOW ONLY DELETES THE ATTRIBUTES OF THE NODE NOT THE ENTIRE NODE.... PLEASE HELP..
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(dataFile);
XmlElement root = xmlDoc.DocumentElement;
XmlNode delNode = root.SelectSingleNode("//website[@name='" + this.cboURLName.Text + "']");
delNode.RemoveAll();
xmlDoc.Save(dataFile);
Dems
your are great.. I highly appreciate your help...
Once again thanks a million.
MSx86
hainm
The following code sample should work:
XmlDocument doc = new XmlDocument();
doc.Load(args[0]);
string text = "abc";
XmlNode parentNode = doc.SelectSingleNode("/data");
XmlNodeList nodeList = parentNode.SelectNodes("./website[@name='abc']");
foreach(XmlNode node in nodeList) {
parentNode.RemoveChild(node);
}
doc.Save(Console.Out);
Thanks,
Priya