0

我有这个 XML 数据

<Address Location="ABC">
   <Add Location="XYZ1" street="street1"  />
   <Add Location="VZC" street="street1" />
</Address>

我想找出<add> --> street 哪个值是street1

我已经尝试如下,没有得到结果

var q = from res in xmlDoc.Descendants("Address")
        where res.Attribute("Location").Value == "ABC"
              && res.Element("Add").Attribute("Location").Value == "VZC"
        select new
               {
                  streetadd= res.Element("Add").Attribute("street").Value,
               };

请有人建议在这种情况下如何检查子元素的条件。

4

1 回答 1

0

尝试这个:

        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
                                };
于 2012-05-10T16:21:03.020 回答