码迷,mamicode.com
首页 > Windows程序 > 详细

C# XDocument

时间:2020-07-03 15:22:41      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:集合   each   查询   文本   方法   处理   文档   sel   cte   

XDocument

说明LINQ处理XML文件的一个类
添加引用

using System.Linq;
using System.Xml.Linq;
using System.Xml.XPath;
引用xml文件
XDocument xml = XDocument.Load("IOS.xml");
根节点
XElement root = xml.Root;

xml查询

  • Xpath查询【推荐方法】

要记得引用 using System.Xml.XPath;

 xml.Root.XPathSelectElement("//XCUIElementTypeApplication");
  • LINQ 查询
  • 遍历Elements然后对比文本或其他属性
foreach (XElement item in xml.Elements())
{
   //xml中的属性都在里面
   c.Attributes()
}

XElement

XDocument代表xml文档,Xelement则代表具体的某个元素节点
获取属性XElement.Attribute(属性名)

获取属性集合XElement.Attributes(属性名)

C# XDocument

标签:集合   each   查询   文本   方法   处理   文档   sel   cte   

原文地址:https://www.cnblogs.com/tangpeng97/p/13230515.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!