Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.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
使用linq从xml检索值_Linq_Linq To Xml - Fatal编程技术网

使用linq从xml检索值

使用linq从xml检索值,linq,linq-to-xml,Linq,Linq To Xml,我有这个XML数据 <Address Location="ABC"> <Add Location="XYZ1" street="street1" /> <Add Location="VZC" street="street1" /> </Address> 在这种情况下,请有人建议如何检查子元素的条件。尝试以下方法: var query = from res in xmlDoc.Descendants("Address"

我有这个XML数据

<Address Location="ABC">
   <Add Location="XYZ1" street="street1"  />
   <Add Location="VZC" street="street1" />
</Address>
在这种情况下,请有人建议如何检查子元素的条件。

尝试以下方法:

        var query = from res in xmlDoc.Descendants("Address")
                                where res.Attribute("Location").Value == "ABC"
                                from child in res.Elements("Add")
                                where child.Attribute("Location").Value == "VZC"
                                select new
                                {
                                    streetadd = child.Attribute("street").Value
                                };

查询没有问题,它工作正常,还返回结果street1,您希望它返回什么?您希望检查什么条件?我需要其地址Location=“ABC”和Add Location=“VZC”的压力的详细信息
        var query = from res in xmlDoc.Descendants("Address")
                                where res.Attribute("Location").Value == "ABC"
                                from child in res.Elements("Add")
                                where child.Attribute("Location").Value == "VZC"
                                select new
                                {
                                    streetadd = child.Attribute("street").Value
                                };