Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

XMLBeans / XPath problem

843834Sep 21 2004 — edited Nov 18 2004
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;
    }

Comments

843834
The path lookup doesn't look very complex. I think it might be complaining about how you are declaring the namespace and doing the lookup in one command.
843834
I discovered on an Apache XMLBeans forum that the Apache XPath engine doesn't have predicates (conditionals I guess?). That's what the author call it. I took out the [id="100"] and it worked. It didn't do what I needed, but at least the code now worked.

So I was frustrated. The message did mention that Bea's version of XMLBeans did have support for predicates. I switch my code and it finally worked as I wanted.

If you want code sample, just ask and I will post.
843834
I'm having the same problem. According to Apache's FAQ, "XmlBeans has a built in engine for very simple XPath expressions. For more advanced XPath expressions Jaxen engine can be used if xbean_xpath.jar is on the classpath. xbean_xpath.jar is available in build\private\lib by running 'ant xbean_xpath.jar'."

But no matter what I do, I can't seem to get xbean_xpath to work. So, now I'm interested in your solution of using Bea's version. How would I get that version? Is there a fee for it?

Thanks,
Kenny
843834
java.lang.UnsupportedOperationException: This query
is too complex to be processed.
In the source for XMLBeans, (
xmlbeans-1.0.3/src/xmlstore/org/apache/xmlbeans/impl/store/XqrlDelegate.java
specifically), you'll see that the rocket scientist who created this code throws an UnsupportedOperationException if it can't find the method for executing the query. The message in the exception is clearly designed to mislead his enemies.

Saxon (http://saxon.sourceforge.net/) has 1000x more robust XQuery support and they have documentation for embedding it in your app.

HTH,
-- /v\atthew
843834
Murphy,

Could you please post your code for me? I'm facing exactly the same problem with predicates. Also, if you have the URL where I can download Bea's implementation jar, please attach that too.

thanks,
Fizal
843834
XMLBeans 1.x can be made to work on complex queries using Jaxen, however, the bigger problem is supporting namespaces.

Using the Jaxen integration the following works:-

selectPath("//OBJECT[@JAVACLASS='com.
nav.engine.NavProcedureUpdate']//OBJECT[(@JAVACLASS='com.
nav.engine.NavState') and (@NAME !='Unrecognized Screen')]");

That's a little more complex than the standard support in XMLBeans on it's own.

:o)
1 - 6
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 16 2004
Added on Sep 21 2004
6 comments
197 views