gpt4 book ai didi

xml - XQuery:创建一个具有给定名称的新元素?

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

我有这样的数据:

    <td>USERID</td>

<td>NAME</td>

<td>RATING</td>

我想把它改造成:

<userid></userid>
<name></name>
<rating></rating>

我该怎么做?

最佳答案

使用 computed element constructor为每个 td 元素生成具有 text 节点的 lower-case 值的元素。

A computed element constructor creates an element node, allowing both the name and the content of the node to be computed.

为了示例,假设您的 XML 位于名为 foo.xml 的文件中,您可以执行如下操作:

<doc>
{
for $name in doc('foo.xml')//td/text()
return element {lower-case($name)} {''}
}
</doc>

产生这个:

<?xml version="1.0" encoding="UTF-8"?>
<doc>
<userid/>
<name/>
<rating/>
</doc>

您还可以评估 lower-case() 函数作为 XPATH 表达式的一部分而不是元素构造函数,如下所示:

<doc>
{
for $name in doc('foo.xml')//td/text()/lower-case(.)
return element {$name} {''}
}
</doc>

关于xml - XQuery:创建一个具有给定名称的新元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2542235/

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