C# XDocument


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM