[英]Querying Linq to xml with an incomplete value
我有一個關於查詢Linq的問題。
例如,我有這個xml:
<output>
<meta>
<generated_at>2009-06-19T16:18:40+00:00</generated_at>
<total_entries>1234</total_entries>
</meta>
<entries>
<entry>
<url><![CDATA[http://www.example.com/]]></url>
<phish_id>123456</phish_id>
<phish_detail_url>http://www.phishtank.com/phish_detail.php?phish_id=123456</phish_detail_url>
<details>
<detail>
<ip_address>1.2.3.4</ip_address>
<cidr_block>1.2.3.0/24</ip_address>
<announcing_network>1234</announcing_network>
<rir>arin</rir>
<detail_time>2009-06-20T15:37:31+00:00</detail_time>
</detail>
</details>
<submission>
<submission_time>2009-06-19T15:15:47+00:00</submission_time>
</submission>
<verification>
<verified>yes</verified>
<verification_time>2009-06-19T15:37:31+00:00</verification_time>
</verification>
<status>
<online>yes</online>
</status>
<target>1st National Example Bank</target>
</entry>
...
</entries>
</output>
如果要獲取值為“ example”或其他不完整值的“ entry”元素,該怎么辦?
謝謝
var example = XDocument.Parse(inStr)
.Descendents("entry")
.Where(e => e.Element("url").Value.Contains("example"))
.FirstOrDefault();
如果有多個可能的元素,則您可能不需要.FirstOrDefault()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.