从 XPath 1.0 中的节点集中获取字符串序列 [英] Get a string sequence from a node-set in XPath 1.0

查看:26
本文介绍了从 XPath 1.0 中的节点集中获取字符串序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 XPath 1.0 来解析 HTML 文件,我想从节点集中获取字符串序列.首先,我选择一个节点集(例如://div),然后我想要该集的每个节点的字符串值.我试过 string(//div) 但它只返回集合中第一个节点的字符串值.

示例:

<div>bbbb<p>aaa</p>

<div>cccc<p>aaa</p>

</foo>

我希望得到类似 ('bbbbaaa', 'ccccaaa') 的结果,但我只得到 'bbbaaa'

解决方案

在 XPath 1.0 中 "节点集的字符串值" 定义为节点集中第一个节点的字符串值.

在 XPath 2.0 中,以下表达式生成 XML 文档中所有 div 元素的字符串值序列:

//div/string(.)

I'm using XPath 1.0 to parse an HTML file and I want to get a string sequence from a node-set. First I select a node-set (eg: //div) and then I want the string-value of each node of the set. I've tried with string(//div) but it only returns the string-value of the first node in the set.

Example:

<foo>  
    <div>  
         bbbb<p>aaa</p>  
    </div>  
    <div>  
         cccc<p>aaa</p>  
    </div>  
</foo>

I expect a result like ('bbbbaaa', 'ccccaaa') but I only get 'bbbaaa'

解决方案

In XPath 1.0 the "string-value of a node-set" is by definition the string value of the first node in the node-set.

In XPath 2.0 the following expression produces a sequence of the string values of all div elements in an XML document:

//div/string(.)

这篇关于从 XPath 1.0 中的节点集中获取字符串序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆