You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Cory Bestgen <co...@bestgen.net> on 2005/09/08 04:41:35 UTC

trying to use xpath and running into problems

I am having trouble getting the selectPath(String) method to work the way
I understand that it should.

I am using xmlbeans 2.0 jdk 1.4.2 and have saxon 8.5.1 on my classpath...

I have attached the sample xml file I have loaded.

When I try to run the follwing code:
String declarations = "declare namespace
osca='http://www.courts.mo.gov/osca'; ";
    declarations += "declare namespace
case='http://www.courts.mo.gov/case-constraint'; ";
    String path = "$this//osca:Case/case:CaseTrackingID/case:ID/text()";
    XmlObject[] x = legalEnvelopeDocument.selectPath(declarations + path);
    System.out.println("Length: " + x.length);
    System.out.println(x.length > 0 ? x[0].toString() : "not found");

I get the following error:
java.lang.RuntimeException:  Trying XBeans path engine... Trying Saxon...
FAILED on declare namespace osca='http://www.courts.mo.gov/osca'; declare
namespace case='http://www.courts.mo.gov/case-constraint';
$this//osca:Case/case:CaseTrackingID/case:ID/text()


When I try the following path with the same above code:
String path = "$this//osca:Case/case:CaseTrackingID/case:ID";

It runs but I get two elements back instead of the one that should be
returned based on the xml document.

Do I misunderstand how xpath is supposed to be used or am I just missing a
. or slash somewhere.