I got this to work. Here's what I did:
1. I built xmlbeans from source. On my initial attempts to do this, I had been getting an error from ant saying that "svn" was not present. I didn't even know what that was; somehow I found out it meant "subversion", which I had heard of, but didn't have installed. I installed that, but it warned me that the Berkeley DB wasn't installed. I went ahead and installed that, and remade subversion, but it still said the Berkely DB wasn't installed so it wouldn't use it. I continued anyway; my real goal was to build xmlbeans. xmlbeans built, and was now a newer version. The jars were in a different place, so I had to update that for XMLBEANS_HOME and in Eclipse, which is what I'm using for development.
There was a new error about an xmlstream error or something. This hadn't occurred before, but was corrected when I found the missing class in one of the jar files: jsr173_1.0_api.jar. Once I added that to the classpath in Eclipse, the program ran. I don't think anything was said in the documentation about having to include that jar on the classpath.
2. The program now ran with the new version of xmlbeans, but it still didn't work. However, I did have a new and somewhat more informative, although still ultimately unsatisfactory,message:
Error: printItems:  Trying XQRL... Trying Saxon... FAILED on $this/fam:GED/fam:fam
[Ljava.lang.StackTraceElement;@229ed4

3. I hit the documentation about xpath to see what I could find. There really isn't any formal xmlbeans xpath documentation, that I could find: the best you can find is some sample programs. I noticed that the sample used a "declare namespace" string in front of the xpath search _expression_. I didn't see why this was necessary if my elements were defined with the default namespace, but tried it anyway. I had some question about how to specify the namespace if I wanted it to be the default namespace: I hadn't used a namespace prefix in my xml.
I had no luck with any of this, EXCEPT: I also saw some positioning of the cursor being done before the searchPath statement, and noticed that, depending on how I positioned the cursor at the beginning, I'd either get the error above or I'd get no error, but nothing would be found. The ones I tried and the results were:
        XmlCursor famCursor = famRecs.newCursor();  //-- create the cursor
        famCursor.toStartDoc();                                 //-- no error
 //       famCursor.toFirstChild();                  //-- no error
 //      famCursor.toNextToken();                //-- error


I figured the no-error, nothing found ones were the
one to do further exploration on.

4. I noticed in the documentation for the cursor.selectPath method that this does not actually advance the cursor; you have to do a cursor.toNextSelection() to actually get to the thing selected. This was helpful.
5. Finally, I downloaded and installed the sample XPathXQuery. I had some problems with this also, because the build.xml wants XMLBEANS_HOME to point to the top directory of your xmlbeans installation, not to the directory with the jars. You also have to have the other jars on the classpath. I verified that the sample ran, but more important, I was able to resolve this question about whether or not to declare a namespace and use the prefix. I looked at the actual xml file being used (employees.xml) and
noticed that this used a default namespace and no prefixes, yet in the "declare namespace" string a prefix was defined, and used
in the subsequent xpath search _expression_. So I used that in mine. By that time, I had done a lot of trial-and-error testing with just about every combination of terms I could think of: very frustrating.

So, by positioning my cursor toStartDoc before the search thus:
famCursor.toStartDoc();
, using the namespace declaration string (which by the way is, as far as I found, not documented except in the example programs, and I think is unique to the xmlbeans xpath):
 
, by defining a namespace prefix in it, and by qualifying the xpath search elements with this prefix, even though the prefix is not used in the actual xml:
     final String famNamespace =
            "declare namespace fam='http://fhuddles.info"+"/family';";
       String searchPath =  "$this/fam:GED/fam:fam";
         famCursor.selectPath(famNamespace+searchPath);

I have been able to get a successful xpath search. I should note that the cursor position toFirstChild(), while it produces no error, does not return any selections from the xpath selectPath. Evidently it positions $this down too far in the DOM.
I also found confusing and apparently contradictory specifications for the search path: some documentation said to use "." for the current position, and the sample used "$this".
OK, those are my results. I feel I have acheived them more through arduous trial-and-error than anything else, and offer my results both for some closure and maybe to help out anyone else who might find himself with a similar problem.
A search on the user list archives sure would be nice!

Regards,

Frank H.



Reply via email to