Hi,
I'm getting
java.lang.UnsupportedOperationException: This query is too complex to be processed. on the method call XmlObject[] h = doc.
selectPath(queryText); I have googled the net looking for answers. I even downloaded XPath Explorer (Eclipse plugin) and my path works there for my XML file, so I'm stumped why it doesn't work in code. Please help!
Here are the assets involved:
The XML data file:
<trx:box xmlns:trx="http://mysite.com/foo">
<trx:transaction>
<trx:id>100</trx:id>
<trx:handler>Dog</trx:handler>
</trx:transaction>
<trx:transaction>
<trx:id>200</trx:id>
<trx:handler>Cat</trx:handler>
</trx:transaction>
<trx:transaction>
<trx:id>300</trx:id>
<trx:handler>Mouse</trx:handler>
</trx:transaction>
</trx:box>
The XSD file:
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:trx="http://mysite.com/foo"
targetNamespace="http://mysite.com/foo"
elementFormDefault="qualified">
<xs:element name="box">
<xs:complexType>
<xs:sequence>
<xs:element name="transaction" type="trx:transaction" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="transaction">
<xs:sequence>
<xs:element name="id" type="xs:string"/>
<xs:element name="handler" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
The .xsdconfig file
<xb:config
xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config"
xmlns:trx="http://mysite.com/foo">
<xb:namespace uri="http://mysite.com/foo">
<xb:package>com.mysite.foo</xb:package>
</xb:namespace>
</xb:config>
The code (don't yell, it's just proof of concept code):
public Handler getHandler(String id) throws Exception
{
Handler handler = null;
BoxDocument doc = BoxDocument.Factory.parse(file);
String nsText = "declare namespace trx='http://mysite.com/foo' ";
String pathText = "$this/trx:box/trx:transaction[trx:id=\"" + id + "\"]/trx:handler";
String queryText = nsText + pathText;
System.out.println(queryText);
XmlObject[] h = doc.selectPath(queryText); // fails here with "This query is too complex to be processed"
Class ch = Class.forName(h[0].xmlText());
handler = (Handler)ch.newInstance();
return handler;
}