xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Hodges <harmo...@swbell.net>
Subject Re: Xalan/Xerces question.
Date Tue, 22 Feb 2000 18:22:59 GMT
I tried your example and it works for some paths, but for others it throws a
NullPointerException.  Is Xalan not ready for use yet?

I'm using JDK 1.2.2, Xalan 0.19.2, Xerces 1.0.1.  Try the path '//B' against
this xml file:

<A>
<B>B1</B>
<B>B2</B>
</A>

I get this exception:

java.lang.NullPointerException:
 at
org.apache.xalan.xpath.MutableNodeListImpl.isNodeAfterSibling(MutableNodeLis
tImpl.java:522)
 at
org.apache.xalan.xpath.MutableNodeListImpl.isNodeAfter(MutableNodeListImpl.j
ava:382)
 at
org.apache.xalan.xpath.MutableNodeListImpl.addNodeInDocOrder(MutableNodeList
Impl.java:333)
 at
org.apache.xalan.xpath.MutableNodeListImpl.addNodeInDocOrder(MutableNodeList
Impl.java:359)
 at
org.apache.xalan.xpath.MutableNodeListImpl.addNodesInDocOrder(MutableNodeLis
tImpl.java:183)
 at
org.apache.xalan.xpath.SimpleNodeLocator.step(SimpleNodeLocator.java:790)
 at
org.apache.xalan.xpath.SimpleNodeLocator.step(SimpleNodeLocator.java:783)
 at
org.apache.xalan.xpath.SimpleNodeLocator.locationPath(SimpleNodeLocator.java
:337)
 at org.apache.xalan.xpath.XPath.locationPath(XPath.java:932)
 at org.apache.xalan.xpath.XPath.execute(XPath.java:1345)
 at org.apache.xalan.xpath.XPath.execute(XPath.java:1223)
 at org.apache.xalan.xpath.XPath.execute(XPath.java:239)
 at XalanTest.Tester.<init>(Tester.java:25)
 at XalanTest.Tester.main(Tester.java:35)


Here's the code for my Tester class:

package XalanTest;

import org.apache.xalan.xpath.*;
import org.w3c.dom.*;

public class Tester {

  public Tester() {
    try {
      org.apache.xerces.parsers.DOMParser dp = new
org.apache.xerces.parsers.DOMParser();
      dp.parse("c:/dev/simple.xml");
      Document doc = dp.getDocument();
      XPathSupportDefault xpath_support = new XPathSupportDefault();
      XPath xpath = new XPath(xpath_support,null);
      XPathProcessorImpl parser = new XPathProcessorImpl(xpath_support);
      xpath.installFunction("document", new
org.apache.xalan.xslt.FuncDocument());
      parser.initXPath(xpath,"//B",null);
      XObject xobject = xpath.execute(xpath_support,doc,null);
      System.out.println("object="+xobject);
    }
    catch (Exception ex) {
      System.out.println("ex="+ex);
      ex.printStackTrace();
    }
  }

  public static void main(String[] args) {
    Tester tester = new Tester();
  }
}



----- Original Message -----
From: Donald Ball <balld@webslingerZ.com>
To: <general@xml.apache.org>
Sent: Monday, February 21, 2000 1:36 PM
Subject: Re: Xalan/Xerces question.


> I can't speak to your exact error below, except that you might want to try
> using an absolute XPath ("/test/foo") rather than a relative ("test/foo").
> One of the ozone guys forwarded me this code snippet:
>
>     protected static final NodeList getNodesByXPath(Node node, String
> path) throws Exception {
>         XPathSupportDefault xpath_support = new XPathSupportDefault();
>         XPath xpath = new XPath(xpath_support,null);
>         XPathProcessorImpl parser = new XPathProcessorImpl(xpath_support);
>         xpath.installFunction("document", new
> org.apache.xalan.xslt.FuncDocument());
>         parser.initXPath(xpath,path,null);
>         XObject xobject = xpath.execute(xpath_support,node,null);
>         return xobject.nodeset();
>     }
>
> and it works like a champ for me.
>
> - donald
>


Mime
View raw message