删除XML使用选定XPath和一个for循环XML、XPath、for

2023-09-04 23:59:13 作者:把难过说给风

目前,我有以下的code:

 声明XPathNodeIterator theNodes = theNav.Select(theXPath.ToString());

而(theNodes.MoveNext())
{
    //一些尝试,我虽然很接近
    //theNodes.RemoveChild(theNodes.Current.OuterXml);
    //theNodes.Current.DeleteSelf();
}
 

我已经设置的XPath什么,我想在XML返回,我想删除一个循环的一切。我曾尝试删除信息的一些方法,但它简化版,像我的语法。我发现微软支持的一个例子: http://support.microsoft.com/kb/317666 但我想用这一点的同时,而不是为每个。

有任何意见或问题是AP preciated。

解决方案

 字符串nodeXPath =你的X路;

XmlDocument的文档=新的XmlDocument();
document.Load(/ *文件路径* /);

XmlNode的节点= document.SelectSingleNode(nodeXPath);
node.RemoveAll();

XmlNode的parentnode = node.ParentNode;
parentnode.RemoveChild(节点);
document.Save(文件路径);
 

bWAPP XML XPath Injection

I currently have the following code:

XPathNodeIterator theNodes = theNav.Select(theXPath.ToString());

while (theNodes.MoveNext())
{
    //some attempts i though were close
    //theNodes.RemoveChild(theNodes.Current.OuterXml);
    //theNodes.Current.DeleteSelf();
}

I have set xpath to what I want to return in xml and I want to delete everything that is looped. I have tried a few ways of deleting the information but it does't like my syntax. I found an example on Microsoft support: http://support.microsoft.com/kb/317666 but I would like to use this while instead of a for each.

Any comments or questions are appreciated.

解决方案

string nodeXPath = "your x path";

XmlDocument document = new XmlDocument();
document.Load(/*your file path*/);

XmlNode node = document.SelectSingleNode(nodeXPath);
node.RemoveAll();

XmlNode parentnode = node.ParentNode;
parentnode.RemoveChild(node);
document.Save("File Path");