Search code examples
c#.netxmlxpath

Why does .NET XPath not like [position() le 10001]


I am passing the following in my C# code (.NET 3.5):

XPathNavigator.
    Compile(/windward-studios/Products/Product/@ProductID[position() le 10001])

and I am getting:

System.Xml.XPath.XPathException occurred
Message='/windward-studios/Products/Product/@ProductID[position() le 10001]' has an invalid token.
Source=System.Xml StackTrace: at MS.Internal.Xml.XPath.XPathParser.CheckToken(LexKind t) at MS.Internal.Xml.XPath.XPathParser.ParsePredicate(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParseStep(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParseRelativeLocationPath(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParseRelativeLocationPath(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParseRelativeLocationPath(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParseRelativeLocationPath(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParseLocationPath(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParsePathExpr(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParseUnionExpr(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParseUnaryExpr(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParseMultiplicativeExpr(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParseAdditiveExpr(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParseRelationalExpr(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParseEqualityExpr(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParseAndExpr(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParseOrExpr(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParseXPathExpresion(String xpathExpresion) at MS.Internal.Xml.XPath.QueryBuilder.Build(String query, Boolean allowVar, Boolean allowKey) at MS.Internal.Xml.XPath.QueryBuilder.Build(String query, Boolean& needContext) at System.Xml.XPath.XPathExpression.Compile(String xpath, IXmlNamespaceResolver nsResolver) at System.Xml.XPath.XPathNavigator.Compile(String xpath) at WindwardReportsDrivers.net.windward.datasource.xml.XPathDataSource.XPathDocNode.SelectNodes(XPathNavigator nav, String xpath, String sortXPath)
InnerException:

Any idea why?

thanks - dave


Solution

  • There's a couple of problems with your query:

    1. It's <=, not le. Remember to escape < if you're writing it inside XML.
    2. You're trying to apply [] on the attribute node - that's probably not what you want. Perhaps you want .../Product[position() le 10001]/@ProductID ?