Xquery和start-with

时间:2016-03-17 14:21:08

标签: xml xquery

我遇到了Xquery的问题。

我有这个XML:

<peliculas>
<pelicula fechaEstreno='2007'>
    <titulo>Los Otros</titulo>
    <director>Alejandro Amenabar</director>
</pelicula>
<pelicula fechaEstreno='1986'>
    <titulo>Sangre Facil</titulo>
    <director>Ethan Coen</director>
</pelicula>
<pelicula fechaEstreno='1990'>
    <titulo>No es pais para viejos</titulo>
    <director>Ethan Coen</director>
    <director>Joel Coen</director>
</pelicula>
<pelicula fechaEstreno='2007'>
    <titulo>The Lovely Bones</titulo>
    <director>Peter Jackson</director>
</pelicula>
</peliculas>

我需要展示&#34; titulo&#34;哪里&#34;导演&#34;开始于&#39; A&#39;。所以我试了一下这个:

for $c in doc('C:\...\pelis.xml') //pelicula
where starts-with($c/director, 'A')
return
<pelicula>
{$c/titulo}
</pelicula>

但我有这个错误:

预期的项目,找到序列:(元素总监{...},...)。

我已经使用&#34;结束了&#34;之前和我认为它的语法类似于&#34;开始 - 用&#34;也是,但它没有用。

我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

对于第三个Exception in thread "main" org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException at org.apache.poi.POIXMLFactory.createDocumentPart(POIXMLFactory.java:65) at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:601) at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:174) at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:279) at sanityTests.ApachePOI.main(ApachePOI.java:20) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:56) at org.apache.poi.POIXMLFactory.createDocumentPart(POIXMLFactory.java:62) ... 4 more Caused by: java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.setLoadEntityBytesLimit(I)Lorg/apache/xmlbeans/XmlOptions; at org.apache.poi.POIXMLTypeLoader.<clinit>(POIXMLTypeLoader.java:50) at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:85) ... 10 more 元素,XPath pelicula返回两个元素的序列

$c/director

另一方面,函数fn:starts-with(...)要求空序列或单个项作为其第一个参数:

(
  <director>Ethan Coen</director>,
  <director>Joel Coen</director>
)

以下是您可以做的事情的示例:

fn:starts-with($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean

使用一些XPath技巧,你甚至可以使它更简洁:

for $c in doc('C:\...\pelis.xml')//pelicula
where
    some $director in $c/director
    satisfies starts-with($director, 'A')
return <pelicula>{
    $c/titulo
}</pelicula>