I’m positive this is a simple question, but I can’t figure it out.
I’m downloading an XML file to a string in C#, and it contains items in the following format:
<attribute name="Make" value="Volvo" />
<attribute name="Color" value="Blue" />
<attribute name="Damage" value="Rear scratched" />
<attribute name="Damage" value="Left hand side dented" />
And all I want to do is get all of the values for “Damage” in the whole document (Regardless of where they fall) into an array. I’ve been playing with XmlDocument / XmlNodeList but I just can’t figure out how to get this working.
I’m half tempted to do it with RegEx but that feels very very dirty.
Use
XDocument:Please note:
This code is relatively simple, because it takes all
attributenodes in the whole document into account.