2011-06-27 3 views
2

私はC#のコード(.NET 3.5)で次のように渡しています:なぜ.NET XPathが好きではない[位置を()ル10001]

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

と私は取得しています:

をSystem.Xml.XPath.XPathException が発生しました
メッセージ= '/ windward-studios/Products/Product/@ ProductID [position() 10001]'に無効なトークンがあります。
ソース= System.XmlののStackTrace:MS.Internal.Xml.XPath.XPathParser.ParsePredicate(ASTノード qyInput)でMS.Internal.Xml.XPath.XPathParser.CheckTokenで (LexKind T) MS.InternalでMS.Internal.Xml.XPath.XPathParser.ParseRelativeLocationPath(ASTノード qyInput)でMS.Internal.Xml.XPath.XPathParser.ParseRelativeLocationPathで.Xml.XPath.XPathParser.ParseStep(ASTノード qyInput) (ASTノード qyInput) MS.Internal.Xml.XPath.XPathParser.ParseRelativeLocationPath(AstNode qyInput) (MS.Internal.Xml.XPath.XPathParser.ParseRelat) MS.Internal.Xml.XPath.XPathParser.ParsePathExprでMS.Internal.Xml.XPath.XPathParser.ParseLocationPath(ASTノード qyInput) でiveLocationPath(ASTノード qyInput) MS.Internal.Xmlで(ASTノード qyInput) 。 XPath.XPathParser.ParseUnionExpr MS.Internal.Xml.XPath.XPathParser.ParseMultiplicativeExpr(ASTノード qyInput)MSにおける でMS.Internal.Xml.XPath.XPathParser.ParseUnaryExpr(ASTノード qyInput) で(ASTノード qyInput) 。 Internal.Xml.XPath.XPathParser.ParseAdditiveExpr(AstNode qyInput) at MS.Internal.Xml.XPath.XPathParser.ParseRelationalExpr(AstNodeMS.Internal.Xml.XPath.XPathParser.ParseEqualityExprでqyInput) (MS.Internal.Xml.XPath.XPathParserでMS.Internal.Xml.XPath.XPathParser.ParseAndExpr(ASTノード qyInput) におけるASTノードqyInput) .ParseOrExpr(ASTノード qyInput)MS.Internal.Xml.XPath.QueryBuilder.BuildでMS.Internal.Xml.XPath.XPathParser.ParseXPathExpresion(文字列 xpathExpresion) で (文字列 クエリ、ブールallowVar、ブール allowKey) MS.Internal.Xml.XPath.QueryBuilder.Build(String クエリ、ブール& needContext) at System.Xml.XPat h.XPathExpression.Compile(文字列 のXPath、れたIXmlNamespaceResolver は、nsResolver)WindwardReportsDrivers.net.windward.datasource.xml.XPathDataSource.XPathDocNode.SelectNodesでSystem.Xml.XPath.XPathNavigator.Compile(文字列 のXPath) で(のXPathNavigator NAV、文字列のXPath、文字列sortXPath)
のInnerException:

任意のアイデアなぜですか?

感謝 - デイブ

答えて

4

あなたのクエリに問題がいくつかあります:

  1. それは<=、ないleです。 <をXMLに書き込む場合は、忘れずに逃げてください。
  2. []を属性ノードに適用しようとしています。これはおそらくあなたが望むものではありません。おそらくあなたは... /Product[position() le 10001]/@ProductID
+0

ありがとうございます - 私は2.0のものだけを忘れています。 (@ProductIDが正しい、動作した後に配置 - 最初の10001ノードが必要で、ノードが属性に必要です。)また、ありがとうございます。 –

+1

@David:しかし、属性ノードの後に​​述語を置くと、 'position()'が属性ノードの位置を返すので(少なくともうまくいけば!)、無関係です。すべての製品にProductID属性がある場合、そのクエリは常にすべての製品を返す必要があります。 –

+0

"le"演算子はXPath 2.0でのみ定義されていますが、式はXPath 1.0プロセッサに渡されています。 –