我是LINQ to XML的新手,想知道是否有人可以幫助我構建以下查詢。LINQ to XML不包含後代包含值的元素的示例
我想返回所有<response>
元素,它們不包含含有「404」的後代<status>
元素。
我的XML如下所示。在這種情況下,只應返回第一個<response>
元素(和後代)。
<multistatus xmlns="DAV:">
<response>
<href>/principals/users/test/</href>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">
<href xmlns="DAV:">/calendars/__uids__/d817aaec-7d24-5b38-bc2f-6369da72cdd9</href>
</calendar-home-set>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/principals/users/test/calendar-proxy-write/</href>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav" />
</prop>
<status>HTTP/1.1 404 Not Found</status>
</propstat>
</response>
<response>
<href>/principals/users/test/calendar-proxy-read/</href>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav" />
</prop>
<status>HTTP/1.1 404 Not Found</status>
</propstat>
</response>
</multistatus>
嗯......你測試過了嗎?對我來說,我得到空的結果。對於命名空間,我使用「DAV:」。 – 2012-07-27 21:36:58
@JonathanWood是的,我做到了。我完全使用了你的問題中的XML。我的整個程序是一個簡單的.NET 4.0 C#控制檯應用程序,它包含將XML存儲到字符串變量以及我的答案中的代碼,僅此而已。你應該得到一個'迴應'回來。 – 2012-07-27 21:41:28
Doh!看起來我的名字空間錯了。您的代碼與廣告一樣工作! – 2012-07-27 22:28:14