Hi

I wish to echo your feelings about the difficulty of using the low-level
XPAth API.
On the one hand, one is cautioned by the XPathAPI javadoc to use these
low-level API's. Yet once one takes this friendly advice, one is down in
the trenches rereading Xalan source files...

So I gave up and tried  Dom4j which gives a simple XPAth query API, which
you can learn to use in about 30 minutes and which you can also optimize by
reusing  XPath instances.

I ran my own informal benchmarks and concluded subjectively, for my
purposes, that DOM4J performed significantly better than Xalan for large
numbers of XPath queries on small documents. Dom4j let me achieve my
functional and performance goals. Xalan XPath seems to require the time to
contribute to its further development, which one does not always have.

-chris




                                                                                
                                                     
                      Christoffer Soop                                          
                                                     
                      <[EMAIL PROTECTED]        To:       [EMAIL PROTECTED]     
                                           
                      .org>                    cc:                              
                                                     
                                               Subject:  Using the low-level 
XPathAPI                                                
                      05/03/2002 05:15                                          
                                                     
                      PM                                                        
                                                     
                      Please respond to                                         
                                                     
                      Christoffer Soop                                          
                                                     
                                                                                
                                                     
                                                                                
                                                     




I having great difficulties understanding the XPath API and would really
apreciate some help.

What I would like to do is to

1. Create several, precompiled XPath expressions
2. On demand parse an XML-document from a java.lang.String and apply the
precompiled XPaths to the parsed document one at a time.

Ideally I would like to accomplish the above using SAX and DTM. If anybody
could supply me with some code that does something similar to this I would
be more than grateful!


Particular questions related to the problem above and my current
understanding of how the Xalan/XPath API works are:

a. How do I create an XPath object independently from an XML-document?

As I understand it creating an XPath instance requires a Prefix-resolver,
and at least org.apache.xml.utils.PrefixResolverDefault requires a Node
from the Document to query.  To avoid this is it ok to implement a dummy
prefix resolver or tom implement one that resolves prefixes based on the
knowledge I have of the documents that will be processed?  Another option
seems to be to use the default resolver with an empty Node or one that
defines relevant namespace attributes.  Is this a good idea?

b. How do I create a DTM document?

c. How do I associate a DTM document with an XPathContext?

d. Can an XPathContext be reused for for different xml documents?

e. What is the value of the root node / when executing an xpath query with
a given xpath-context?  (Can it be assumed to be 0 for example?)

I have a working solution that does not use precompiled xpaths but wraps an
XPathContext in an internal reprsentation of an xpath (xml) document, se
the attached java source code.  The worst problem aassociated with the code
is that i takes an org.w3c.dom.Document and that the only way I know how to
create a Document (or Node) is using DOM.

Sincerely,

             Christoffer Soop



--
Christoffer Soop <[EMAIL PROTECTED]>
+46 (0)730 74 68 15 / +46 (0)8 651 24 36




Reply via email to