gpt4 book ai didi

xml - 使用 XPath 拆分节点值

转载 作者:数据小太阳 更新时间:2023-10-29 01:42:24 24 4
gpt4 key购买 nike

XPath 中是否有某种split() 函数?假设我有这个 XML:

<root>
<path>C:\folder\filename</path>
</root>

我想检索文件名,我该怎么做?我知道我可以这样获取节点值:

//path/text()

如何只获取文件名? (我知道有一个 concat() 函数,所以也许有一个 split() 函数?)

最佳答案

如果您有一个支持 xpath-2.0 的 API,您可以通过两种方式解决这个问题:

替换技术

尝试使用:

fn:replace(string,pattern,replace)

例如

fn:replace(//path/text(),".*/","")

分词技术

您可能会从标记化中获得一些好处:

fn:tokenize(string,pattern)

例如(感谢马丁)

tokenize(/root/path, '\\')[last()]

w3schools xml processing "xsl functions" documentation

关于xml - 使用 XPath 拆分节点值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4255154/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com