It's Friday and my mind already seems to have moved to weekend thinking.
Given this xml structure -
<?xml version="1.0" encoding="utf-8"?>
<results requiredAttribute="somedatahere">
<entry>
<!-- Xml structure in here -->
</entry>
<entry>
<!-- Xml structure in here -->
</entry>
<entry>
<!-- Xml structure in here -->
</entry>
</results>
And this code(cut down to the core code) that uses an xmlreader to read the data and asychronously return the data -
response = (HttpWebResponse)request.GetResponse();
using (var reader = XmlReader.Create(response.GetResponseStream()))
{
Logger.Info("Collector: Before attempt to read data for {0}", url);
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "entry")
{
var el = XElement.ReadFrom(reader) as XElement;
if (el != null)
yield return el;
}
}
}
What is the easiest way to retrieve the value from the attribute requiredAttribute?
Key point to consider is that I don't at any point want to read the full xml file in as the file could be very big. Also the data is coming from an HttpStream so you can't always guarantee that the data is complete and subsequently that the outer result element is well formed. This seems to rule out reading the result element and then iterating through it's children.