deleting specific node in xml

后端 未结 2 846
眼角桃花
眼角桃花 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条回答
  •  Happy的楠姐
    2020-12-09 21:55

    Assuming you have loaded that into an XmlDocument named doc:

    XmlElement el = (XmlElement)doc.SelectSingleNode("/company/employee[id=2]");
    if(el != null) { el.ParentNode.RemoveChild(el); }
    

提交回复
热议问题