您的位置:首页 > 其它

LINQ TO XML 添加与判断

2009-12-29 18:36 330 查看
知识落伍了,记录下来

xml文件原形:

<items>
<item kind="a">ba</item>
</items>

<items>  <item kind="a">ba</item></items>


节点判断

Dim doc = XDocument.Load("post.xml")    Dim query = From p In doc.Descendants("item") _
Where p.Attribute("kind").Value = "a" And p.Value = "b"
If query.Count > 0 Then
存在()
End If


节点添加

Dim doc = XDocument.Load("post.xml")

doc.Element("items").Add(New XElement("item", "zz", New XAttribute("kind", "aa")))
doc.Save("post.xml")


为什么实例化时XElement时 item 可以转换成 System.Xml.Linq.XName 对象?这里不懂。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: