简体   繁体   English

XQuery,检查元素为空?

[英]XQuery, check element empty?

How can i check if a node has no text in it? 如何检查节点中是否没有文本? I can use string($node)="" because a node can be like this 我可以使用string($ node)=“”,因为节点可以像这样

<node>              </node>

what i mean that, it can contain spaces but no text in it?? 我的意思是,它可以包含空格,但不能包含任何文字?

We got caught by this very thing where spaces and line breaks where causing us some grief when checking to see if a node really had text. 我们被这种东西所吸引,因为在检查节点是否确实有文本时,空格和换行符使我们有些悲伤。 In the end we created a function that examines the text nodes of an element and we check to see if any of those text nodes contain any word characters. 最后,我们创建了一个检查元素的文本节点的函数,并检查其中是否有任何文字字符。 Here's what it looks like: 看起来是这样的:

some $child in $node/text() satisfies (fn:matches($child, "\w+"))

If one of the child text nodes has any word characters, we defined that as having text and of course if it has no text nodes or has text nodes that don't have word characters, we defined that as not having text. 如果子文本节点之一具有任何文字字符,我们将其定义为具有文本,当然,如果它不具有文本节点或具有不具有文字字符的文本节点,则将其定义为不具有文本。

看一下fn:normalize-space函数。

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

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