HtmlAgilityPack XPath无效令牌

时间:2014-02-17 21:51:23

标签: windows-phone-7 xpath html-agility-pack

偶尔看到无效的令牌异常。每次都不抛出异常,并且XPath是静态的。不知道发生了什么。

doc.DocumentNode.SelectSingleNode("//*[contains(@itemprop,'softwareVersion')]");

Message:

'//*[contains(@itemprop,'softwareVersion')]' has an invalid token.


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.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 System.Xml.XPath.XPathExpression.Compile(String xpath, IXmlNamespaceResolver nsResolver)
at System.Xml.XPath.XPathNavigator.Select(String xpath)
at HtmlAgilityPack.HtmlNode.SelectSingleNode(String xpath)

我有时也会看到它,同样的无效令牌异常

doc.DocumentNode.SelectNodes("//*[contains(@class,'item')]");

1 个答案:

答案 0 :(得分:0)

尝试不使用“*”:

doc.DocumentNode.SelectSingleNode("//[contains(@itemprop,'softwareVersion')]");