且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用c#从XML中删除父标记

更新时间:2023-02-15 11:45:51

你可以尝试像这样..



1)阅读< parent>使用内部xml标记和复制所有子节点

2)现在转到MainParents的根节点

3)现在用你的xml字符串替换内部xml字符串第一步阅读。



i认为它会解决你的问题。



但我不能承受站起来为什么你需要这个。您可以通过步骤父标记直接访问子节点。
you can try like this..

1) read the <parent> tag and copy all child node using inner xml
2) now go to the root node that is MainParents
3) now replace the inner xml string with your xml string which is read in first step.

i think it will solve your problem.

but i can't under stand why you need this. you can directly access the child node by steping on the Parent tag.


试试这个..



try this..

foreach (XmlNode chkNode in nodes)
{                
    string currentName = "Test 1";
    if (!nameDict.ContainsKey(currentName))
    {
        XmlNode parent = chkNode.ParentNode;
        parent.ParentNode.RemoveChild(parent);
    }
}