C# – Read XML element attributes with XElement (Linq)

XML elements can have attributes, which are key-value pairs. To read the attributes, use XElement to parse the XML string (from the Linq-to-Xml API). Then you can use these two methods for getting attributes: Once you have the attributes, use the XAttribute.Value property to read the attribute’s string value. Here’s an example of getting all … Read more

C# – Find XML element by name with XElement (Linq)

Use the XElement class (from the Linq-to-Xml API) to search for XML elements by name. There are two main methods you can use to do this: These return the matching elements as an IEnumerable<XElement>. You can then use Linq methods (or a foreach loop) to do whatever you want with these elements (such as outputting … Read more