I'm using the following XML:
<?xml version="1.0" encoding="windows-1252"?>
<hexML>
<head>
<title><![CDATA[ ]]></title>
<description><![CDATA Releases XML]]></description>
<flastmod date="2014-09-24T16:34:23 CET"/>
</head>
<body>
<press_releases>
<press_release id="1796256" joint_id="383320" language="fr" type="5">
<published date="2014-06-19T11:55:09 CET"/>
<categories>
<category id="75" label="French" keywords="language"/>
</categories>
<headline><![CDATA[Test Release for Website 3]]></headline>
<ingress></ingress>
<location href="http://rthrthrthrtrt.com/test.xml"/>
</press_release>
</press_releases>
</body>
</hexML>
我将尝试通过这段代码块获取数据:
cp[cpt, 0] = (from c in xdoc.Descendants("press_release")
where (int)c.Attribute("id") == r
select c.Element("headline").Value).Single();
cp[cpt, 1] = (from c in xdoc.Descendants("press_release")
where (int)c.Attribute("id") == r
select (c.Element("published").Attribute("date").Value)).ToString();
cp[cpt, 3] = (from c in xdoc.Descendants("press_release")
where (int)c.Attribute("id") == r
select c.Element("location").Attribute("href").Value).ToString();
第一条指令返回正确结果: Test Release for website 3。 另外两条指令返回的是"System.linq.Enumerable+WhereSelectEnumerableIterator'2[system.XML.Linq.Xelement,System.String]"。 谢谢您的帮助。 注:我使用的是.NET V3.5。