XQuery错误:XPTY0019:' /'的第一个操作数的必需项类型是node();

时间:2016-04-06 05:49:01

标签: xml xquery

我想通过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:首先需要的项目类型   &#39; /&#39;的操作数是node();提供的值具有项类型xs:string

enter image description here

1 个答案:

答案 0 :(得分:1)

("mondial-3.0.xml")只是包含单个项目的字符串序列。它不是node()的一种,因此是错误。我相信您想要调用doc()函数来从文件中读取数据:

let $countries := doc("mondial-3.0.xml")//......
let $cities := doc("mondial-3.0.xml")//city
......