You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Christoffer Soop <ch...@soop.org> on 2002/05/03 17:15:59 UTC

Using the low-level XPathAPI

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 <ch...@soop.org>
+46 (0)730 74 68 15 / +46 (0)8 651 24 36

Re: Using the low-level XPathAPI

Posted by Christoffer Soop <ch...@soop.org>.
It doesn't really solve my problem - using SAX with the Xalan/XPath API but the page you referred to seems to suggest that it is OK to create a Node object simply to hold the namespace for the document and that in turn makes it possible to create precompiled XPath expressions.

Thanks!

/Christoffer Soop


On Fri, May 03, 2002 at 11:57:33AM -0400, Elliotte Rusty Harold wrote:
> >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!
> >
> 
> Soem of this is demoed at 
> http://www.cafeconleche.org/books/xmljava/chapters/ch16s04.html
> 
> I don't use DTM at all, but this may be helpful.
> -- 
> 
> +-----------------------+------------------------+-------------------+
> | Elliotte Rusty Harold | elharo@metalab.unc.edu | Writer/Programmer |
> +-----------------------+------------------------+-------------------+
> |          The XML Bible, 2nd Edition (Hungry Minds, 2001)           |
> |             http://www.cafeconleche.org/books/bible2/              |
> |   http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/   |
> +----------------------------------+---------------------------------+
> |  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      |
> |  Read Cafe con Leche for XML News: http://www.cafeconleche.org/    |
> +----------------------------------+---------------------------------+

-- 
Christoffer Soop <ch...@soop.org>
+46 (0)730 74 68 15 / +46 (0)8 651 24 36