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

前端之家收集整理的这篇文章主要介绍了xml – XQuery:创建一个给定名称的新元素?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有数据如:
<td>USERID</td>

    <td>NAME</td>

    <td>RATING</td>

我想把它变成:

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

我该怎么做?

@H_404_9@
@H_404_9@
使用 computed element constructor生成具有每个td元素的文本节点的小写值的元素.

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>

您还可以将小写()函数作为XPATH表达式的一部分而不是元素构造函数,如下所示:

<doc>
{
for $name in doc('foo.xml')//td/text()/lower-case(.)
return element {$name} {''}
}
</doc>
@H_404_9@ 原文链接:https://www.f2er.com/xml/292815.html

猜你在找的XML相关文章