System.Xml.XPath.XPathException: 'Namespace Manager or XsltContext needed. This query has a prefix,



昨天我发布了这个问题:

https://stackoverflow.com/questions/56182368/html-agility-pack-select-node-after-particular-paragraph

我使用解决方案解决了:htmlSnippet.DocumentNode.SelectNodes('//p[text()="targetWord"]/following-sibling::ul[1]//li')

今天,在另一个项目上,具有相同的配置和HTML敏捷包版本I在标题中获得错误消息。我该怎么办?

System.Xml.XPath.XPathException: 'Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.'

抛出异常的代码:

var htmlDoc = new HtmlDocument();
            htmlDoc.LoadHtml(htmlText);

            //var ulCollection = htmlDoc.DocumentNode.SelectNodes("//ul");
            var tasksNodesCollection = htmlDoc.DocumentNode.SelectNodes("//p[TextValue()="Paragraph:"]/following-sibling::ul[1]//li");

您正在寻找的文本中有一个结肠。

htmlDoc.DocumentNode.SelectNodes("//p[TextValue()="Paragraph:"]

解析器认为这是XML名称空间预选赛。使用逃生形式"对于结肠。

已解决!!!我使用text((=而不是textValue((=我不知道为什么昨天起作用!!!

相关内容

最新更新