繁体   English   中英

使用XQuery搜索具有特定详细信息的Node

[英]Using XQuery to search for Node having specific details

我不是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结构,那是我的主要缺点

你必须提供的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()

您可以尝试以下方法:

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}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM