tags:

views:

44

answers:

1

I need to evaluate multiple XPath expressions against a document. The documents are large, so we're using a streaming parser. The XPath expressions simply return the value of a node. I need to order the XPath expressions so that they are in document order (since once I evaluate an expression, evaluation of the next expression begins at the point in the document where the last value was found). I have the schema for the document, but I'm unsure how to use it to establish the order.

I'm using C# with .NET 4, if that matters. If someone could point me in the right direction, I'd appreciate it!

+1  A: 

This is not achievable without posing some limitations on the XPath expressions.

For example, any XPath expression that contains the axes descendant::, descendant-or-self::, ancestor::, ancestor-or-self::, preceding::, following:: and even the axes preceding-sibling:: and following-sibling:: -- may require reading the XML document completely.

In case the XPath expressions don't contain these axes, you could arrange them by the number of location steps (they also shouldn't contain parent:: or ..), and you can temporarily stop evaluating any expression with number of location paths smaller than the current depth.

Dimitre Novatchev