XQuery Error: XPTY0019: Required item type of first operand of '/' is node();
XQuery Error: XPTY0019: Required item type of first operand of '/' is node();
我想通过 xquery 从 xml 获取一些数据。原来的 xml 是这样的:
<mondial>
<country id="AAA" name="BBB" gdp_total="XXX" population_growth="XXX">
<name>BBB</name>
<city id="CCC" country="AAA">
<name>DDD</name>
<population>XXXX</population>
<located_at type="XX"/>
</city>
...
</country>
...
</mondial>
我写了一个这样的 XQuery:
declare function local:globals_1(){
let $countries:=("mondial-3.0.xml")//country[@gdp_total > number(100000) and @population_growth > number(0.3)]
let $cities:=("mondial-3.0.xml")//city
for $country in $countries
for $city in $cities
where $country/@id = $city/@country
order by number($city/@population)
return $city
};
<globals>
{local:globals_1()}
</globals>
出现错误:
F [Saxon-PE XQuery 9.6.0.7] XPTY0019: Required item type of first
operand of '/' is node(); supplied value has item type xs:string
("mondial-3.0.xml")
只是一个包含单个项目的字符串序列。它不是一种 node()
,因此是错误的。我相信您想调用 doc()
函数而不是从文件中读取数据:
let $countries := doc("mondial-3.0.xml")//......
let $cities := doc("mondial-3.0.xml")//city
......
我想通过 xquery 从 xml 获取一些数据。原来的 xml 是这样的:
<mondial>
<country id="AAA" name="BBB" gdp_total="XXX" population_growth="XXX">
<name>BBB</name>
<city id="CCC" country="AAA">
<name>DDD</name>
<population>XXXX</population>
<located_at type="XX"/>
</city>
...
</country>
...
</mondial>
我写了一个这样的 XQuery:
declare function local:globals_1(){
let $countries:=("mondial-3.0.xml")//country[@gdp_total > number(100000) and @population_growth > number(0.3)]
let $cities:=("mondial-3.0.xml")//city
for $country in $countries
for $city in $cities
where $country/@id = $city/@country
order by number($city/@population)
return $city
};
<globals>
{local:globals_1()}
</globals>
出现错误:
F [Saxon-PE XQuery 9.6.0.7] XPTY0019: Required item type of first operand of '/' is node(); supplied value has item type xs:string
("mondial-3.0.xml")
只是一个包含单个项目的字符串序列。它不是一种 node()
,因此是错误的。我相信您想调用 doc()
函数而不是从文件中读取数据:
let $countries := doc("mondial-3.0.xml")//......
let $cities := doc("mondial-3.0.xml")//city
......