How to get the attribute value of xml using LINQ to XML?
问题 I have the following xml schema. <Rooms> <Room RoomNumber="room1" EMAIL="ssds@dsfd.com" dsfdd=""/> <Room RoomNumber="room2" EMAIL="ssds@sdd.com" dsfdd=""/> </Rooms> I have to return Email address based on the input(input to program is room number). How i can achieve this using LINQ to XML? 回答1: var doc = XDocument.Load(myXmlFilePath); // or doc = XDocument.Parse(myXmlString); string roomNumber = "room1"; var emailQuery = from room in doc.Root.Elements("Room") where (string)room.Attribute(