運用 XElement 有兩種方式 可以 將 Node 的資料刪除
Dim Xdoc as Xelement = Xelement.Load( "C:\text.xml")
比如 想要將
<Recipe>
<RcpNo>1011</RcpNo>
<RcpName>123</RcpName>
</Recipe>
重 節點中鐘移除
1. 法一: 用反選的方式,將 不一樣的挑出來
XDoc = New XElement(<RecipeList><%= From rcp In XDoc.Elements("Recipe")
Select rcp
Where rcp.Element("RcpNo").Value <> recipe.RcpNo %>
</RecipeList>)
2. 法二: 用正選的方式,在將之移除
Dim selectXelement As System.Collections.Generic.IEnumerable(Of XElement) = From rcp In Xdoc.Elements("Recipe")
Select rcp
Where rcp.Element("RcpNo").Value = rcpNo.ToString
selectXelement.Remove()
===================================================
test.xml 內的資料
<?xml version="1.0" encoding="utf-8"?>
<RecipeList>
<Recipe>
<RcpNo>1001</RcpNo>
<RcpName>SEtest2</RcpName>
</Recipe>
<Recipe>
<RcpNo>1002</RcpNo>
<RcpName>ABCD</RcpName>
</Recipe>
<Recipe>
<RcpNo>1005</RcpNo>
<RcpName>RStest1</RcpName>
</Recipe>
<Recipe>
<RcpNo>1011</RcpNo>
<RcpName>123</RcpName>
</Recipe>
</RecipeList>
- Jan 14 Sat 2012 20:25
XML 與 Linq (三) XML 配合 Linq 刪除 Node
close
全站熱搜
留言列表
發表留言