xml XQuery:返回元素的值而不是元素本身

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1155248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 12:37:53  来源:igfitidea点击:

XQuery: Return value of an element rather the element itself

xmlxquery

提问by kpozin

I have an XML document that contains the following

我有一个包含以下内容的 XML 文档

...
<foo>abc</foo>
...

If I evaluate

如果我评价

return $xml//foo

I get back

我回来了

<foo>abc</foo>

Is there any way to get just abcinstead?

有什么办法可以abc代替吗?

回答by Harold L

Yes, you want the text() function for selecting the child text:

是的,您需要 text() 函数来选择子文本:

return $xml/text()

Be careful if you will have nested tag structure inside $xml though, because this will only go one level deep for text nodes. If you want all of the text nodes together, stripping out other XML structure, this will do arbitrarily deep:

但是,如果您将在 $xml 中嵌套标记结构,请小心,因为对于文本节点,这只会深入一层。如果你想把所有的文本节点放在一起,去掉其他的 XML 结构,这将是任意深度的:

return $xml//text()

回答by Oliver Hallam

Use the string function to get the string content of a node.

使用字符串函数获取节点的字符串内容。

return string($xml)

回答by SeeJay

To return only the data inside an element you can use:

要仅返回元素内的数据,您可以使用:

return data($xml)

回答by savemaxim

Cast to xs:string {xs:string($xml/foo)}

转换为 xs:string {xs:string($xml/foo)}

回答by Aniruddha Jagtap

OSB (oracle service bus) users can use following function.

OSB(oracle 服务总线)用户可以使用以下功能。

fn-bea:serialize($xml)

fn-bea:serialize($xml)