我是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