XDocument中的XELEMENT如何删除?
How do delete XELEMENT in XDocument?
<Settings>
<List>
<Holder>
<Name>Peter</FolderName>
<Age>35</Age>
</Holder>
<Holder>
<Name>John</FolderName>
<Age>25</Age>
</Holder>
<Holder>
<Name>Micheal</FolderName>
<Age>45</Age>
</Holder>
<Holder>
<Name>Kenin</FolderName>
<Age>28</Age>
</Holder>
</List>
</Settings>
如何完全移除 "Kenin" 支架 下面的代码只是删除名称,但我想删除 kenin 持有人完全
Dim e = From element In _xdoc.Descendants("Name") Where element.Value = "Kenin" Select element
e.Remove()
Select 父元素应该是名称的包装元素:
Dim e = From element In _xdoc.Descendants("Name") Where element.Value = "Kenin" Select element.Parent
e.Remove()
怎么样,
'for testing
Dim xe As XElement = <Settings>
<List>
<Holder>
<Name>Peter</Name>
<Age>35</Age>
</Holder>
<Holder>
<Name>John</Name>
<Age>25</Age>
</Holder>
<Holder>
<Name>Micheal</Name>
<Age>45</Age>
</Holder>
<Holder>
<Name>Kenin</Name>
<Age>28</Age>
</Holder>
</List>
</Settings>
xe...<Name>.Where(Function(el) el.Value = "Kenin").Select(Function(el) el.Parent).Remove()