XQuery的类型不匹配

问题描述:

declare variable $fb := doc("factbook.xml")/mondial; 
for $c in $fb//country 
where ($c/encompassed/@continent = 'f0_119') and ($c/@population < 100000) 
return concat('Country: ',$c/name, ', Population: ',$c/@population); 

返回:XQuery的类型不匹配

Type Error: Type of value ' 

() 
' does not match sequence type: xs:anyAtomicType? 
At characters 11681-11698 
At File "q2_3.xq", line 4, characters 13-67 
At File "q2_3.xq", line 4, characters 13-67 
At File "q2_3.xq", line 4, characters 13-67 

但是,如果我不做CONCAT回报,只是名称或人口将工作,最奇怪的是我还有一个程序:

declare variable $fb := doc("factbook.xml")/mondial; 
for $c in $fb//country 
where $c/religions = 'Seventh-Day Adventist' 
order by $c/name 
return concat('Country: ',$c/name, ', Population: ',$c/@population); 

返回语法是完全相同的,但是,它的工作原理。 为什么会发生这种情况?

没有看到你的数据的例子,这是不可能肯定的说,但如果$c/name返回多个值,那么你的错误是有道理的。如果有多个name元素,您是否有任何结果?

+0

你是对的,有国家/名称,但也有国家/城市/名称,所以我该如何修改它,使其只显示国家/名称 –

+1

@NeoZhang'country/city/name' would not成为一个问题。尝试将你的return语句改为'($ c/name)[1]'。 – wst

+0

非常感谢!!!!!!!你救了我的生命 –