You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Christian Geuer-Pollmann <ma...@nue.et-inf.uni-siegen.de> on 2001/02/28 14:55:20 UTC
How do I get a NodeList using an XPath ?
Hi,
I'm looking for a way to let an XPath String select nodes from a document
and returning me a NodeList. Maybe I'm too complicated, but the only way I
saw was the function
org.apache.xpath.XPathAPI.selectNodeList()
but it doen't work, because XObject.nodeset() always returns an error. Is
there an easier way than the below one?
Thanks in advance,
Christian
---------------
String xpath = new String("(//. | //@* | //namespace::*)");
InputSource in = new InputSource(new FileInputStream(filename));
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
Document doc = dfactory.newDocumentBuilder().parse(in);
NodeList nl = XPathAPI.selectNodeList(doc.getDocumentElement(),
xpath, doc.getDocumentElement());
for (int i=0; i<nl.getLength(); i++) {
Node n = nl.item(i);
System.out.println(n.getNodeName());
}
---------------
Re: How do I get a NodeList using an XPath ?
Posted by Christian Geuer-Pollmann <ma...@nue.et-inf.uni-siegen.de>.
Dear Gary
--On Mittwoch, 28. Februar 2001 08:34 -0800 Gary L Peskin
<ga...@firstech.com> wrote:
>> I saw was the function
>> org.apache.xpath.XPathAPI.selectNodeList()
>> but it doen't work, because XObject.nodeset() always returns an error. Is
>> there an easier way than the below one?
>>
> I'm not sure where your error is. Do you have the same problem
> described here:
>
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=702
Yes, that was the solution. Thank you.
Christian
Re: How do I get a NodeList using an XPath ?
Posted by Gary L Peskin <ga...@firstech.com>.
Christian Geuer-Pollmann wrote:
>
> Hi,
>
> I'm looking for a way to let an XPath String select nodes from a document
> and returning me a NodeList. Maybe I'm too complicated, but the only way I
> saw was the function
>
> org.apache.xpath.XPathAPI.selectNodeList()
>
> but it doen't work, because XObject.nodeset() always returns an error. Is
> there an easier way than the below one?
>
> Thanks in advance,
Christian --
I'm not sure where your error is. Do you have the same problem
described here:
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=702
Gary