First off if you check the documentation for
XmlTextReader (
http://msdn.microsoft.com/en-us/libr...extreader.aspx) it is recommended you don't create one directly but instead use
XmlReader.Create to obtain one....
Regarding the performance of XLinq vs XmlTextReader though it doesn't seem to be clear cut in all scenarios, googling for comparison results seem to indicate
XmlTextReader is generally the fastest but results is more code that is often harder to read and maintain, the performance benefits seem to lessen as the size of the document increases as well.
The Xlinq should look something like
Code:
Dim doc = XDocument.Load("c:\tmp\test.xml")
Dim x = Aggregate node In doc.Element("Animal").Elements("p")
Where (node.Attribute("name").Value = "Akita Inu")
Into Count = Count(), Total = Sum(CInt(node.Value))
Debug.WriteLine("Count {0}, Total {1}", x.Count, x.Total)
Which effectively loads the xml document into an
XDocument and then will perform an aggregate of all child elements of
Animal that have the name
p and contain an attribute called
name with a value of "
Akita Inu", this information would then have a count and a sum performed on it, the
Debug.WriteLine simply displays these two values.
Not sure if this is supported in 2008 but just out of interest 2010 would have allowed a slightly cleaner XML like syntax of
Code:
Dim doc = XDocument.Load("c:\tmp\test.xml")
Dim x = Aggregate node In doc.<Animal>.<p>
Where node.@name = "Akita Inu"
Into Count = Count(), Total = Sum(CInt(node.Value))