我有一个关于查询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”元素或其他一些不完整的值,我该怎么做?
谢谢
答案 0 :(得分:0)
var example = XDocument.Parse(inStr)
.Descendents("entry")
.Where(e => e.Element("url").Value.Contains("example"))
.FirstOrDefault();
如果有多个可能的元素,那么您可能不需要.FirstOrDefault()