使用 xpath 从 xml 元素中提取值

K3it4r0

我想使用 xpath 从 xml 元素中的 url 字符串中提取值,例如:

<Artist_Export>
<Geonames>http://www.geonames.org/3175121/l-aquila.html</Geonames>
</Artist_Export>

在这种情况下,我想从http://www.geonames.org/3175121/l-aquila.html 中提取“3175121”

您是否有一些关于如何使用 xpath 执行此操作的线索?

编辑:我尝试使用:

substring(/Artist_Export/Geonames, string-length(/Artist_Export/Geonames) -20) 

但我只得到了它的最后一部分。应该使用 substring(stringoffsetlength) ,它“返回字符串的一部分。该部分从偏移量(这是一个数字)开始,并且与长度(也是一个数字)提供的值一样长。” 但我真的不知道如何使用它

K3it4r0

好的,我找到了解决方案。你应该使用

子字符串(/路径/子路径,starting_char_numer,number_of_chars)

例如,在这种情况下

<Artist_Export>
<Geonames>http://www.geonames.org/3175121/l-aquila.html</Geonames>
</Artist_Export

如果要提取“3175121”,正确的命令是

substring(/Artist_Export/Geonames, 25,7) 

希望它对其他人有用:)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章