deleting specific node in xml

后端 未结 2 850
眼角桃花
眼角桃花 2020-12-09 21:12

I need to delete specific employee node and also its child node based on the value of id. For example, here I need to delete employee tag with id=\"2\".

<         


        
2条回答
  •  生来不讨喜
    2020-12-09 21:40

    Try this one

     XmlDocument xmlDoc = new XmlDocument();
     XmlNode nodeToDelete = xmlDoc.SelectSingleNode("/root/XMLFileName[@ID="+nodeId+"]");
                if (nodeToDelete != null)
                {
                    nodeToDelete.ParentNode.RemoveChild(nodeToDelete);
                }
                xmlDoc.Save("XMLFileName.xml")
    

提交回复
热议问题