使用linq从xml检索值
我有这个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"
<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
};