<test-case name="SuccessfulOneTimePayment" executed="True" result="Success" success="True" time="211.262" asserts="9">
<categories>
<category name="Regression" />
</categories>
<properties>
<property name="TestcaseId" value="70592" />
</properties>
</test-case>
任何人都可以幫助我從這個XML獲取TestcaseId值= 70592?如何使用LINQ獲取xml中的元素/元素下的屬性值
var testcaseid = xml.Root.Descendants("test-case").Elements("categories").Elements("properties")
.Where(s => s.Attribute("name") != null)
.ToList();
我試過上面的代碼,這不是幫助我。
您的查詢表明,性質是類別的孩子,而事實並非如此。嘗試'xml.Root.Descendants(「test-case」)。元素(「屬性」)'。 – shahkalpesh
XPath不會爲此服務嗎?爲什麼選擇LINQ? – shahkalpesh
@Shahkalpesh查看下面的Cuong Le的答案,您會發現Linq在Databse到XML的許多來源中有多直觀和美妙。誰真的想學習另一種語言來使用XML? – Alireza