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

被折叠的 条评论
为什么被折叠?



