Tag: xpath

使用XPath忽略大小写的SelectNodes

我在查找XPath中包含忽略字符大小写的字符串的元素时遇到问题。 我想在HTML页面中找到所有id为id的节点都包含文本“footer”,忽略它的大写或小写。 在我的例子中,我有一个不同的html文本,如下所示: some text some text some text some text 我需要使用XPath选择所有节点(或任何情况下在id中使用“footer”一词的任何组合)。 目前我正在使用此xpath,但不适用于UpperCase id “//*[contains(./@id, ‘footer’)]/@id” 我用translate()完成了几个测试但是没有按照我的预期工作。 任何的想法? 编辑:我正在使用HtmlAgilityPack与XPath 1.0版本的工作。

通过XPath和HtmlAgilityPack获取属性的值

我有一个HTML文档,我用XPath解析它。 我想获得元素输入的值,但它不起作用。 我的Html: 我的代码: using HtmlAgilityPack; HtmlAgilityPack.HtmlDocument doc; HtmlWeb hw = new HtmlWeb(); HtmlNodeCollection node = doc.DocumentNode.SelectNodes(“//input/@value”); string s=node[0].InnerText; 所以我想得到这个值:“10743” (我不介意另外给出答案的标签。)

如何以编程方式在XPathExpression实例中使用XPath函数?

我当前的程序需要以编程方式使用创建XPathExpression实例来应用于XmlDocument。 xpath需要使用一些XPath函数,如“ends-with”。 但是,我找不到在XPath中使用“ends-with”的方法。 一世 它抛出exception如下 未处理的exception:System.Xml.XPath.XPathException:需要命名空间管理器或XsltC ontext。 此查询具有前缀,变量或用户定义的函数。 System.Xml.XPath.XPathNavigator.Evaluate(XPathExpression expr,XPathNodeIt erator context)中的MS.Internal.Xml.XPath.CompiledXpathExpr.get_QueryTree() 在System.Xml.XPath.XPathNavigator.Evaluate(XPathExpression expr) 代码是这样的: XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(@” Hello World “); XPathNavigator navigator = xdoc.CreateNavigator(); XPathExpression xpr; xpr = XPathExpression.Compile(“fn:ends-with(/myXml/data, ‘World’)”); object result = navigator.Evaluate(xpr); Console.WriteLine(result); 我试图在编译表达式时更改代码以插入XmlNamespaceManager,如下所示 XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(@” Hello World “); XPathNavigator navigator = xdoc.CreateNavigator(); XmlNamespaceManager nsmgr […]