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(屬性名)