0

我不是 XQuery 方面的专家,我不得不搜索大量文件,XML 文档有这样的结构,

<files>
<file>
    <name>1</name>
    <contents>
        <content>games</content>
        <content>movies</content>
    </contents>
</file>
<file>
    <name>2</name>
    <contents>
        <content>games</content>
        <content>picture</content>
        <content>work</content>
    </contents>
</file>

它就像用户我有一组可能的内容(“游戏”,“电影”),我必须返回名称

到目前为止我只写了这个

for $x in /files/file
    return $x/content

我想知道 XQuery 是否可以做到这一点?如果可能的话,给我一些指导,我不知道所有的 xquery 结构,这是我的主要缺点

4

2 回答 2

0

您还必须contents在 xpath 中提供元素,因为它包含content元素值。如果你只想要的值,你可以试试这个content

for $x in /files/file/contents/content
return xs:string($x)

你也可以试试这个

for $x in /files/file/contents/content
return $x/text()
于 2013-04-11T07:36:20.180 回答
0

你可以试试这个:

let $data:=
<files>
<file>
    <name>1</name>
    <contents>
        <content>games</content>
        <content>movies</content>
    </contents>
</file>
<file>
    <name>2</name>
    <contents>
        <content>games</content>
        <content>picture</content>
        <content>work</content>
    </contents>
</file>
</files>

for $cont in $data//content
return element contents{$cont}
于 2018-06-13T13:16:06.837 回答