You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Donald Ball <ba...@webslingerZ.com> on 2000/02/17 08:07:33 UTC

Help with XPath support in Xalan

Hey guys. I'm trying to use Xalan to give me XPath support. Given a DOM
Document and a String xpath, I'd like to get the list of Nodes that the
xpath refers to. I've been poking through the API for many minutes now and
haven't managed to figure out how to do so; seems like a simple operation,
can someone clue me in? Thanks.

- donald


Re: Help with XPath support in Xalan

Posted by Lars Martin <la...@softwarebuero.de>.
Hi Donald,

Thu, 17 Feb 2000 Donald Ball wrote:
>Hey guys. I'm trying to use Xalan to give me XPath support. Given a DOM
>Document and a String xpath, I'd like to get the list of Nodes that the
>xpath refers to. I've been poking through the API for many minutes now and
>haven't managed to figure out how to do so; seems like a simple operation,
>can someone clue me in? Thanks.
>
>- donald

I�ve attached a code fragment of our XPathQueryImpl from the 'ozone' Project.
Maybe you have the time to look at the sources at http://www.ozone-db.org.

I hope I removed all ozone specific things...

<------>

import org.w3c.dom.*;
import org.apache.xalan.xpath.*;
 
public class XPathQueryImpl {

    transient protected XPathSupportDefault xpathSupport;
    transient protected XPathProcessorImpl parser;
    transient protected XPath xpath;

    public XPathQueryImpl () {
        // Since we don't have a XML Parser involved here, install some
        // default support for things like namespaces, etc.
        xpathSupport = new XPathSupportDefault ();

        // Create the XPath object.
        xpath = new XPath (xpathSupport, null);

        // Create a XPath parser.
        parser = new XPathProcessorImpl(xpathSupport);

        // Since raw XPath doesn't have a document function, you have to 
        // install one.  The same will be true of a few other functions 
        // that are currently built-in to XPath.
        xpath.installFunction("document", new org.apache.xalan.xslt.FuncDocument());
        }

    public XObject execute (String qString, Document pDoc) 
                            throws org.xml.sax.SAXException {

        parser.initXPath (xpath, qString, null);

        // execute the XPath query on the specified Document
        XObject result = xpath.execute (xpathSupport, (Node)pDoc.getDocumentElement(), null);

        return result;
        }

    }

<------>

Regards,
Lars
--
________________________________________________________________
Lars Martin                         mailto:lars@softwarebuero.de
softwarebuero m&b (SMB)              http://www.softwarebuero.de