LINQ overview阅读笔记。

LINQ to XML overview

LINQ是Language-Integrated Query 的缩写。

是否是依托dotnet丰富的metadata实习的呢?

可以支持内存之内修改XML数据,以及类似XPath/XQuery那样的查询功能。

LINQ to XML developers

……

LINQ to XML is an XML programming interface

LINQ to XML与DOM的区别:

  • 更轻量
  • 能够利用到语言的特性
    • 强类型,编译时检查,调试支持等等

可以把查询结果作为参数传给XElement和XAttribute等标的的建构器。这个叫functional construction。

文中给了两个例子,但是没有细看。

还可以使用LINQ to XML来:

  • 从文件或数据流加载XML
  • 序列化XML
  • 使用functional contruction创建XML
  • 查询XML
  • 操弄XML树体
  • 使用XSD校验XML树体
  • 转化XML树体

Create XML trees

一个创建XML树体的例子:

XElement contacts =
new XElement("Contacts",
    new XElement("Contact",
        new XElement("Name", "Patrick Hines"),
        new XElement("Phone", "206-555-0144",
            new XAttribute("Type", "Home")),
        new XElement("phone", "425-555-0145",
            new XAttribute("Type", "Work")),
        new XElement("Address",
            new XElement("Street1", "123 Main St"),
            new XElement("City", "Mercer Island"),
            new XElement("State", "WA"),
            new XElement("Postal", "68042")
        )
    )
);