You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Alec Lebedev <al...@nextpage.com> on 2007/08/13 04:14:51 UTC
converting XQuery results to Java objects generated by XmlBeans
XmlObject.execQuery() returns an array of XmlObjects. But how do I
convert this array to an array of classes generated by XmlBeans?
Thanks.
RE: converting XQuery results to Java objects generated by XmlBeans
Posted by Alec Lebedev <al...@nextpage.com>.
It turns out that execQuery returns an array of XmlBeans-generated class
only if there is an XSD <element> declared for the elements returned by
execQuery. It is not sufficient just to have an XSD type defined for
those elements. Consider the following XSD and XML:
XSD:
<schema ...>
<complexType name="RootDefinition">
<sequence>
<element name="dataSource"
type="tns:DataSource" minOccurs="1" maxOccurs="unbounded"></element>
</sequence>
</complexType>
<complexType name="DataSource">
<attribute name="name" type="ID"
use="required"></attribute>
</complexType>
<element name="definition"
type="tns:RootDefinition"></element>
<!--<element name="dataSource"
type="tns:DataSource"></element>-->
</schema>
XML:
<definition ..>
<dataSource name="ds-live"/>
</definition>
The following query will return XmlObject[] with the dataSource element
commented out in XSD and will return DataSourceDocument[] when
dataSource is un-commented in the XSD.
XQuery:
"for $x in .//xq:definition/xq:dataSource return $x"
I don't understand why I have to have the element definition (in
addition to the type definition) in the XSD for XmlBeans to properly
cast the result of the query?
Thanks.
________________________________
From: Alec Lebedev [mailto:alec.lebedev@nextpage.com]
Sent: Sunday, August 12, 2007 8:15 PM
To: user@xmlbeans.apache.org
Subject: converting XQuery results to Java objects generated by XmlBeans
XmlObject.execQuery() returns an array of XmlObjects. But how do I
convert this array to an array of classes generated by XmlBeans?
Thanks.