// Get the Attribute name from within the query
XDocument Facility = XDocument.Load("facility.xml");
var query = from cFa in Facility.Descendants("cofacility").Elements("facility")
from cNo in cFa.Elements("company")
where cNo.Attribute("no").Value == number
select cFa.Elements("contact").Attributes("name");
foreach (var q in query)
{
foreach(string contact in q)
{
Console.WriteLine(contact.ToString());
}
}
// Get the Attribute name after the query when you enumerate the query itself
XDocument Facility = XDocument.Load("facility.xml");
var query = from cFa in Facility.Descendants("cofacility").Elements("facility")
from cNo in cFa.Elements("company")
where cNo.Attribute("no").Value == number
select cFa.Elements("contact");
foreach (var q in query)
{
foreach (XElement contact in q)
{
Console.WriteLine(contact.Attribute("name").Value);
}
}
|