You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Mike Engelhart <me...@earthtrip.com> on 2000/06/23 00:03:54 UTC

XPath help

Hi,

I'm working on side project to work with Cocoon to develop the XML
equivalent of the JDK's java.util.ResourceBundle using XML documents rather
than simple Properties lists.

In my current incarnation, I have 2 ways to get the string values out of the
files.  One is a simple getString(String xPath) which takes an xpath string
and using the XPathAPI.java sample code gets an Element and returns it's
TEXT_NODE string value.   Simple enough.  The other method (which I think
will be more useful for what I'm envisioning) is two steps.  One is a method
getRole(String xPath) which takes an xpath string and returns a Node and
then to get the string you want, you would call getString(Node role, String
key) which would again return the TEXT_NODE string value.  This way you can
use the "role" over and over to point to the section of the XML structure
you're interested in.   With ResourceBundle's you generally have to
instantiate a new ResourceBundle to do something like this.

I'm just starting out with XPath (from a Java perspective especially) so I'm
not sure how to go about some of these things which is why I'm using the
XPathAPI class that comes with Xalan-J.
Scott had mentioned on the Cocoon-dev list that you can precompile an XPath
to speed things up.  I'm not sure where to begin to do this.   Can you point
me to the appropriate part of the API or some sample code.
Also is this as fast as passing a reference to a Node and then just doing a
simple Xpath to get to the element desired.

Also is there any difference in lookup performance when you're looking for
attributes vs. elements to do the lookup on?
example:

        <meal code="VGML">
            <name>Vegetarian Meal</name>
        </meal>
    ****versus****
        <meal>
            <code>VGML</code>
            <name>Vegetarian Meal</name>
        </meal>


Thanks for any help,

Mike