xPath Evaluate vs XPathNodeIterator

380 Views Asked by At

I am searching the fastest way to count some tags in a huge xml-file (120MB)

long Quantity;
XPathDocument xDocData = new XPathDocument(str_File_path);
XPathNavigator xNavData = xDocData.CreateNavigator();

//Option 1
XPathExpression xExp = xNavData.Compile("sum(Tag/Value)");
Quantity = Convert.ToInt64(xNavData.Evaluate(xExp));

//Option 2
XPathNodeIterator xNodeIter = xNavData.Select(xExp);
while(xNodeIter.MoveNext())
{
    Quantity += xNodeIter.Current.ValueAsLong;
}

Any suggestions?

greetings and thanks in advance

1

There are 1 best solutions below

0
On

Are you only looking to get counts from this file, or do you actually need the contents for some other purpose? If you just need the counts, and the file is that large, it's probably more efficient to use a SAX Parser, catch the events on the relevant nodes, and increment on those events.