I'm using C# to handle an XML file with a repeating structure. The pseudo-document is as follows:
<Root>
<Element attribute=1> 123 </Element>
<Element attribute=2> 456 </Element>
<Element attribute=3> 789 </Element>
</Root>
I'm trying to work with all of this data at once. I figured out (after much experimentation and reading) how to write all of the data within each to (sort of) an array for easy access later. For now, I've just been printing this data to the console for debugging purposes:
XmlNodeList values = xmlDoc.GetElementsByTagName("Element");
for (int i=0; i <= values.Count; i++)
{
Console.WriteLine(values[i].InnerText);
}
That part works great. Now, I'm trying to access the attributes of in a similar fashion, and it's just not panning out. After some searching, I came up with
values = xmlDoc.GetElementsByTagName("Element").GetAttribute("attribute");
but that didn't work. How can I add these attributes to a array?