【问题标题】:How To remove a specific tag from XElement如何从 XElement 中删除特定标签
【发布时间】:2014-07-08 08:10:35
【问题描述】:

请考虑XML

<Employees>
    <Person>
        <ID>1000</ID>
        <Name>Nima</Name>
        <LName>Agha</LName>
    </Person>
    <Person>
        <ID>1002</ID>
        <Name>Ligha</Name>
        <LName>Ligha</LName>
    </Person>
    <Person>
        <ID>1003</ID>
        <Name>Jigha</Name>
        <LName>Jigha</LName>
    </Person>
</Employees>

我将它加载到Xelement 变量中。现在如何从XML 上方删除第二个Person 标记?

谢谢

【问题讨论】:

    标签: c# xml c#-4.0 xelement


    【解决方案1】:

    如果唯一的条件是第二个节点Person,你可以使用这个。

    XElement  rootElement = .... // init your rootElement as you want 
    
    rootElement.Elements("Person").Skip(1).Remove() ; 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-22
      • 1970-01-01
      • 2017-07-23
      相关资源
      最近更新 更多