Thanks for the reply!  Some further comments though...

On Fri, May 03, 2002 at 11:43:19AM -0400, Joseph Kesselman/CAM/Lotus wrote:
> 
> You're talking about stuff that's at the Xalan implementatin level, not at
> the XPathAPI level...
Well, yes!  The problem I having with using the XPathAPI class is that I would 
like to use SAX and that all methods in the XPathAPI-class require 
org.w3c.dom.Node objects.  And that seems to imply that I have to use a 
DOMBuilder, right?

On top of that, quoting the JavaDoc for the XPathAPI "A faster way is to 
precompile the XPaths using the low-level API, and then just use the XPaths 
over and over" - is begging people like me to try to do just that! :-)

> > c. How do I associate a DTM document with an XPathContext?
> 
> That gets done when you invoke XPathAPI. The DTM is created in the context
> of a specific DTM Manager, and the XPathContext, when instantiated, obtains
> a DTM Manager to use for this purpose.
See above!
 
> > 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?)
> 
> Do you mean XSLT value, or DTM Node Handle? Generally, as noted above, you
> shouldn't be attempting to work with the DTM APIs directly unless you have
> very special needs; they're part of Xalan's internals, not part of the
> intended public API.
The special needs is that I would like to use SAX and not DOM for the 
XML-documents.  

It is a DTM Node Handle.  Currently I am using

        execute( mXPathContext, mNode, mPrefixResolver );

on an XPath instance and mNode is obtained from

        mNode = mXPathContext.getDTMHandleFromNode( document );

And it works fine.  (I figured this out using part of the code from the 
XPathAPI class, I think...)  My main problem, still, is how to substitute this 
for something that doesn't use a org.w3c.dom.Node-object and secondary to 
precompile XPaths.  I figure I can use the getDTM( Source source...) method in 
XPathContext but that returns a DTM instead of a node handle - thereby making 
me think about what node handle to use.

/Christoffer

(BTW - seem like I forgot to include the code I was referring to, so I have 
attached it to this mail instead.)

> 
> 
> 

-- 
Christoffer Soop <[EMAIL PROTECTED]>
+46 (0)730 74 68 15 / +46 (0)8 651 24 36
package com.score.data;

import com.score.logging.Logger;

import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;
import org.apache.xpath.objects.XObject;
import org.apache.xml.utils.PrefixResolver;
import org.apache.xml.utils.PrefixResolverDefault;

import org.w3c.dom.Document;

import javax.xml.transform.TransformerException;

public class XPathDocument {

// -- fields -------------------------------------------------------------------

  public static final Logger log = 
    Logger.Factory.getInstance( XPathDocument.class );

  private int mNode;
  private XPathContext mXPathContext;
  private PrefixResolver mPrefixResolver;                                     

// -- constructors -------------------------------------------------------------

  public XPathDocument( Document document ) {
      // save relevant document information
      mPrefixResolver = 
        new PrefixResolverDefault( document.getDocumentElement() );

      mXPathContext = new XPathContext();
      mNode = mXPathContext.getDTMHandleFromNode( document );
      
  }

// -- methods ------------------------------------------------------------------

  public XObject evaluate( String xpathString ) 
      throws TransformerException {

    XPath xpath = new XPath( xpathString, null, mPrefixResolver, XPath.SELECT );
    return xpath.execute( mXPathContext, mNode, mPrefixResolver );
  }
}


Reply via email to