How to delete a xml node with all attributes and start, end tag of the xml node in c#-- urgent
-
Hello every one! I have a little problem of deleting xml node. I have deleted successfully the attributes of node but opening and closing tag of node was not deleted and . But i have to delete also the opening and clsing tag ofthe node means I have to remove every thing of .How can I do this. following is the structure of my xml file -------------------------------------------------------- 0 1.0.1 c1f13323-209b-4b0e-ad8d-d34f64d34c28 2007-10-25T11:47:10.515625+05:30 SUBHASH\Login Subhash C:\Documents and Settings\Login Subhash\Desktop\main.html Adding New Html Help 3 ... .... -------------------------------------------------------- following is my c# code -------------------------------------------------------- //int intRefId = Convert.ToInt32(Request.QueryString["RefId"]); int intRefId = 3; string strXPath = "/LinkInformation/ScreensToSupport/ScreenToSupport/SupportItems/ScreenSupportItem[RefId='" + intRefId + "']"; XmlNode newParent = doc.SelectSingleNode(strXPath); XmlNodeList newChildNodeList = newParent.ParentNode.ChildNodes; foreach (XmlNode node1 in newChildNodeList) { foreach (XmlNode node in node1) { if (node.Name == "LinkURL" && node.InnerText == hdntxtUrlLink.Text) { intCount++; } if (node.Name == "LinkText" && node.InnerText == hdntxtUrlTitle.Text) { intCount++; }
-
Hello every one! I have a little problem of deleting xml node. I have deleted successfully the attributes of node but opening and closing tag of node was not deleted and . But i have to delete also the opening and clsing tag ofthe node means I have to remove every thing of .How can I do this. following is the structure of my xml file -------------------------------------------------------- 0 1.0.1 c1f13323-209b-4b0e-ad8d-d34f64d34c28 2007-10-25T11:47:10.515625+05:30 SUBHASH\Login Subhash C:\Documents and Settings\Login Subhash\Desktop\main.html Adding New Html Help 3 ... .... -------------------------------------------------------- following is my c# code -------------------------------------------------------- //int intRefId = Convert.ToInt32(Request.QueryString["RefId"]); int intRefId = 3; string strXPath = "/LinkInformation/ScreensToSupport/ScreenToSupport/SupportItems/ScreenSupportItem[RefId='" + intRefId + "']"; XmlNode newParent = doc.SelectSingleNode(strXPath); XmlNodeList newChildNodeList = newParent.ParentNode.ChildNodes; foreach (XmlNode node1 in newChildNodeList) { foreach (XmlNode node in node1) { if (node.Name == "LinkURL" && node.InnerText == hdntxtUrlLink.Text) { intCount++; } if (node.Name == "LinkText" && node.InnerText == hdntxtUrlTitle.Text) { intCount++; }
-
Use an XPath statement to find the node you want to remove then call
node.ParentNode.RemoveChild(node)
XmlNode node = doc.SelectSingleNode("//x/y/z/ScreenSupportItem");
node.ParentNode.RemoveChild(node);Thanks a lot sir, its working fine....