C# 使用linq从xml中读取特定元素
我正在尝试使用c#使用谷歌API检索邮政编码。 如何为以下xml编写linq查询C# 使用linq从xml中读取特定元素,c#,linq,google-api,C#,Linq,Google Api,我正在尝试使用c#使用谷歌API检索邮政编码。 如何为以下xml编写linq查询 <address_component> <long_name>United States</long_name> <short_name>US</short_name> <type>country</type> <type>political</type> </address_com
<address_component>
<long_name>United States</long_name>
<short_name>US</short_name>
<type>country</type>
<type>political</type>
</address_component>
<address_component>
<long_name>94043</long_name>
<short_name>94043</short_name>
<type>postal_code</type>
</address_component>
美国
美国
国家
政治的
94043
94043
邮政编码
如果您试图获取邮政编码值,则:
var res = (from el in xmlElm.Descendants("address_component")
where el.Element("type").Value == "postal_code"
select el).FirstOrDefault();
请参见.var res=(来自xmlElm.substands(“地址”组件)中的el,其中xmlElm.Value==“邮政编码”选择el).FirstOrDefault();我尝试了这个,但得到了空结果