Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用linq从xml中读取特定元素_C#_Linq_Google Api - Fatal编程技术网

C# 使用linq从xml中读取特定元素

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

我正在尝试使用c#使用谷歌API检索邮政编码。 如何为以下xml编写linq查询

  <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();我尝试了这个,但得到了空结果