XElement employee = XElement.Parse(""); string name = employee.Attribute("name").Get (); Console.WriteLine(name); // Output: John Doe
XElement contacts = XElement.Parse("In this example, we create an XElement object that represents a collection of contact elements in XML. We use the Descendants method to retrieve all contact elements, and then use LINQ to filter the collection to find the contact element with the name attribute equal to "Alice". Finally, we use the Element method to retrieve the phone child element of the selected contact element, and then use the Get method to extract the element value as a string. The System.Xml.Linq namespace is part of the .NET Framework class library, which is included in the standard installation of Microsoft Visual Studio. There is no separate package library required to use this namespace."); string alicePhone = contacts.Descendants("contact").First(c => (string)c.Attribute("name") == "Alice").Element("phone").Get (); Console.WriteLine(alicePhone); // Output: 1234567890