如何计算XML中的元素数量? [英] how to count the number of elements in XML?

查看:382
本文介绍了如何计算XML中的元素数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找有关数据库中数据的基本元数据.具体来说,由根text元素替代的line元素的数量.

I'm looking to get basic metadata about the data within a database. Specifically, the number of line elements which are surrouned by the root text element.

与我期望COUNT返回SQL的方式类似-一个整数.

Analogous to what I'd expect COUNT to return in SQL -- a single integer.

数据库:

thufir@dur:~/flwor/group$ 
thufir@dur:~/flwor/group$ basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
> 
> open people
Database 'people' was opened in 225.24 ms.
> 
> xquery /
<text>
  <line>people</line>
  <line>joe</line>
  <line>phone1</line>
  <line>phone2</line>
  <line>phone3</line>
  <line>sue</line>
  <line>cell4</line>
  <line>home5</line>
  <line>alice</line>
  <line>atrib6</line>
  <line>x7</line>
  <line>y9</line>
  <line>z10</line>
</text>
Query executed in 215.13 ms.
> 
> exit
See you.
thufir@dur:~/flwor/group$ 

行数:

thufir@dur:~/flwor/group$ 
thufir@dur:~/flwor/group$ basex each.xq 
1
2
3
4
5
6
7
8
9
10
11
12
13thufir@dur:~/flwor/group$ 

代码:

xquery version "3.0";

for $line in db:open("people")
for $index at $count in $line/text/line
return $count

推荐答案

我想您只是想使用count(/text/line).

这篇关于如何计算XML中的元素数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆