我无法从 xml 获取属性值。我正在使用 Google 自定义搜索 API。
var results =
(from r in res.Descendants("R")
where r.Element("T") != null
select new GoogleSearchResultItem(
new PageSummary
{
Title = r.Element("T").Value,
LinkURL = r.Element("U").Value,
Description = r.Element("S").Value
}));
它适用于 T、U、S 元素,但是当我尝试获取属性 programid 时,我得到了 null。
这是 XML:
<R N="1">
<U>
Link to somepage
</U>
<T>
<b>Title</b>
</T>
<S>
Summary
</S>
<LANG>sv</LANG>
<Label>_cse_1h5bojdlb5c</Label>
<PageMap>
<DataObject type="metatags">
<Attribute name="displaydate" value="20121028"/>
<Attribute name="programid" value="2519"/>
<Attribute name="formatid" value="116"/>
</DataObject>
</PageMap>