cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary L Peskin <ga...@firstech.com>
Subject Re: Xalan2: XpathAPI Problem
Date Mon, 23 Oct 2000 22:14:15 GMT
Carsten Ziegeler wrote:
> 
> Hello,
> 
> after a successful update to the latest cocoon/xalan2 release, we still have problems
with the org.apache.xpath.XPathAPI class:
> 
> A method-call XPathAPI.selectSingleNode(testFragment, "test") returns null for the following
fragment:
> 
> <test>
>   <a/>
> </test>
> 
> "testFragment" is a DocumentFragment containing the "test"-node.

The following code (adapted from ApplyXPath) works for me with the
latest XalanJ2 build from CVS:

import org.apache.xpath.XPathAPI;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; 

import org.apache.serialize.OutputFormat;
import org.apache.xml.serialize.transition.XMLSerializer;

public class TestXPath
{
  
  /** Main method to run from the command line.    */
  public static void main (String[] args)
  {
    System.out.println("<output>");
    DocumentFragment docFrag;
	  Element test = null;
    Element aElem = null;

    try {
      DocumentBuilderFactory dfactory =
DocumentBuilderFactory.newInstance();
	    DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
      Document doc = docBuilder.newDocument();
      docFrag = doc.createDocumentFragment();
      test = doc.createElement("test");
      aElem = doc.createElement("a");
      test.appendChild(aElem);
      docFrag.appendChild(test);
    }
    catch (ParserConfigurationException pce) {
      pce.printStackTrace();
      return;
    }
    catch(Exception e1) {
      e1.printStackTrace();
      return;
    }


    Node n = null;
    try {
        n = XPathAPI.selectSingleNode(docFrag, "test");
    }
    catch (Exception e2) {
      System.err.println("selectNodeIterator threw: " + e2.toString() +
" perhaps your xpath didn't select any nodes");
      e2.printStackTrace();
      return;
    }
    XMLSerializer xmlser = new XMLSerializer(System.out, new
OutputFormat());
    try {
      xmlser.serializeXPathReturnNode(n);
    }
    catch (Exception e3) {
      e3.printStackTrace();
      return;
    }
    System.out.println("</output>");
  }
  
} // end of class TestXPath

Perhaps you could include the actual code that's giving you problems and
we can take a look.

Gary

Mime
View raw message