xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Hodges <harmo...@swbell.net>
Subject Xalan/Xerces question.
Date Mon, 21 Feb 2000 18:10:37 GMT
I'm trying to use Xalan's XPath to search a document (we used to use XQL but that seems dead).
 I looked all through the docs but could find very little about how to apply an XPath to a
document.  I found some sample code on Deja.com:

    XPath xpath = new XPath();
    XPathProcessorImpl xparser = new XPathProcessorImpl();
    XercesLiaison liaison = new XercesLiaison();
 
    xparser.initXPath(xpath, "test/foo", null);
    XObject obj = xpath.execute(liaison,doc,0);
    String foo = obj.str();
 


I tried this code with Xalan 0.19.2 and Xerces 1.0.1 (latest I could find at the site) and
it throws this exception:

java.lang.NullPointerException
 at org.apache.xalan.xpath.xml.XMLParserLiaisonDefault.getNamespaceOfNode(XMLParserLiaisonDefault.java:1065)
 at org.apache.xalan.xpath.SimpleNodeLocator.nodeTest(SimpleNodeLocator.java:1786)
 at org.apache.xalan.xpath.SimpleNodeLocator.findChildren(SimpleNodeLocator.java:908)
 at org.apache.xalan.xpath.SimpleNodeLocator.step(Compiled Code)
 at org.apache.xalan.xpath.SimpleNodeLocator.step(Compiled Code)
 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(Compiled Code)
 at org.apache.xalan.xpath.XPath.execute(Compiled Code)
 at com.smackdownlabs.XQLSearch.doQuery(XQLSearch.java:150)

The problem is with these 2 lines of code and an assumption they make about the document:
      String nodeName = n.getNodeName();
      int indexOfNSSep = nodeName.indexOf(':');

'n' at this point is the first child of the Document.  It has no name for some reason.  A
null is reterned from n.getNodeName() and the next line throws the exception all the way out.

Is there a different version I should be running?  Is something wrong with the way I created
my document?  Here's how I did that:

  private static org.apache.xerces.parsers.DOMParser dp = new org.apache.xerces.parsers.DOMParser();
  public static Document parseDocument(String uri) throws Exception {
    dp.parse(uri);
    Document doc = dp.getDocument();
    dp.reset();
    return doc;
  }

Any help would be appreciated.  The current docs on Xalan are very difficult to understand.
 Are there better docs someplace?


Mime
View raw message