XQuery Expression learning

本文深入探讨了如何使用XML语法进行数据检索、过滤、排序和整合,包括使用for、where、order和return语句进行复杂操作,以及如何直接获取数据和使用内置函数。文章还详细解释了比较运算符的使用,提供了XML数据处理的基础语法规则和注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

open the file: doc("xxx.xml")

 

doc("xxx.xml")/bookstore/book[conditon clause]

 

for, where, order, return

 

doc("xxx.xml")/bookstore/book[price>20]/title

=

for $x in doc("xxx.xml")/bookstore/book

where $x/price>20

order by $x/title

return $x/title

 

integrate with html tags

<ul>

for $x in doc("xxx.xml")/bookstore/book/title

oder by $x

return <li>($x)</li>

</ul> 

 

get the data directly use the data() function

ex:

<ul>

for $x in doc("xxx.xml")/bookstore/book/title

return <li>(data|($x))</li>

</ul>

 

basic syntax rules

comment: (:  I am comment :)

"if-then-else": 

for $x in doc("xxx.xml")/bookstore/book

return if ($x/@attribute="hey")

then <child>(data($x/title))</child>

else <adult>(data($x/title))<adult>

comparisons:

one group: =, !=, <, <=, >, >=

another group: eq, ne, lt, le, gt, ge

what's the difference? see the follow two examples

$bookstore//book/@q > 20   --> if any items fulfill the condition,  then return true

$bookstore//book/@q lt 20   --> only one item fulfill the condition, then return true

 

use function

default functions: upper-case, substring, data, and so on...

custom function:

declare function prefix:function_name($parameter AS datatype)

AS returnDataType{

  ...

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值