LINQ to XML 简单范例

前端之家收集整理的这篇文章主要介绍了LINQ to XML 简单范例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

可当成读取配置文件的方式使用


范例档:https://msdn.microsoft.com/zh-tw/library/bb669158.aspx
教学说明:https://msdn.microsoft.com/zh-tw/library/bb387041.aspx

static void ReadFromXML()
{
    try
    {
        XElement root = XElement.Load("../../App_Data/XML01.xml");
        XNamespace aw = "http://www.adventure-works.com";

        Console.WriteLine(root.Attribute(aw + "PurchaSEOrderNumber").Value);
        Console.WriteLine(root.Attribute(aw + "OrderDate").Value);

        IEnumerable
  

 
  
  address = from el in root.Elements(aw + "Address") where (string)el.Attribute(aw + "Type") == "Billing" select el; foreach (XElement el in address) Console.WriteLine(el); foreach (XElement el in address) Console.WriteLine(el.Element(aw+"Zip").Value); } catch (Exception e) { Console.WriteLine(e.Message); } } 

 

输出结果:

99503
1999-10-20

  

 
Tai Yee 8 Oak Avenue Old Town PA 95819 USA
95819

原文:大专栏  LINQ to XML 简单范例

猜你在找的XML相关文章