zoukankan      html  css  js  c++  java
  • linq to xml

    XDocument doc = new XDocument(
            new XElement("BundleConfig",
                new XElement("Scripts",
                    new XElement("Add",
                        new XAttribute("name", "~/bundles/jquery"),
                        new XAttribute("value", "~/Scripts/jquery-1.9.1.js")
                        )
                    ),
                new XElement("Styles",
                    new XElement("Add",
                        new XAttribute("name", "~/bundles/jqueryui"),
                        new XAttribute("value", "~/Content/themes/base/jqueryui-1.9.1.css")
                        )
                    )
                )
            );
    doc.Save("BundleConfig.xml");
    
    doc.Load("BundleConfig.xml");
    XElement root = doc.Element("BundleConfig").Element("Scripts");
    
    var result = from script in root.Elements()
                    where script.Name == "Add"
                    select script;
    
    foreach (XElement item in result)
    {
        Console.WriteLine("name:{0},src:{1}",
            item.Attribute("name").Value,
            item.Attribute("value").Value);
    }
    
    Console.WriteLine(doc);

    创建、保存、读取、查询。

  • 相关阅读:
    多项式模板整理
    广大附中2019CSP模拟day6
    2019正睿CSP-S模拟赛十连测day6
    NOIP2020 游记
    NOI2020 退役记
    CSP2019 退役记
    目录
    NOI Online 提高
    后缀数组
    待学
  • 原文地址:https://www.cnblogs.com/xwgli/p/3306667.html
Copyright © 2011-2022 走看看