can not get selectSingleNode to compile

R

Richard Saville

I am trying to use the XPath method selectSingleNode but the compiler gives
the error "cannot find symbol".

I have the following imports:

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.*;

These line compile and execute:
oRoot = doc.getDocumentElement();
oNode = oRoot.getFirstChild();

These lines will not compile:
oNode = selectSingleNode( oRoot, "memberID");
oNode = oRoot.selectSingleNode( oRoot, "memberID");

I have tried using various imports that have xPath but the compiler always
says "does not exist"
import weblogic.apache.xpath;
import org.jdom.xpath.*;

I'm sure I am missing something basic here. Please help!
 
M

Martin Honnen

Richard said:
I am trying to use the XPath method selectSingleNode but the compiler gives
the error "cannot find symbol".

I have the following imports:

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.*;

These line compile and execute:
oRoot = doc.getDocumentElement();
oNode = oRoot.getFirstChild();

These lines will not compile:
oNode = selectSingleNode( oRoot, "memberID");
oNode = oRoot.selectSingleNode( oRoot, "memberID");

I don't think a Node in the W3C DOM has a method named selectSingleNode,
where did you get the idea it has one?
The W3C DOM Level 2 Node (as implemented in Java 1.4) is documented here:
<http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247>
the Level 3 Node (as implemented in Java 1.5) here:
<http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-1950641247>

DOM Level 2 has no XPath support, DOM Level 3 has an XPath module but
Java 1.5 has choosen to implement its own XPath API and not the W3C DOM.
Thus if you want to use XPath with Java 1.5 you would need to use
javax.xml.xpath.*
 
R

Richard Saville

Martin:

Thanks for the reply.

I looked in the two links you provided but I can not find selectSingleNode.
I don't have to use the W3C dom, I will use anything. I am pulling data from
a webService into an applet. I just need to process the XML response. What
dom and xPath would you recommend?

Thanks
 
M

Martin Honnen

Richard Saville wrote:

I looked in the two links you provided but I can not find selectSingleNode.

That's what I said, I provided the links so that you can look at the API
for alternatives if you want to use the W3C DOM.
I don't have to use the W3C dom, I will use anything. I am pulling data from
a webService into an applet. I just need to process the XML response. What
dom and xPath would you recommend?

If it is an applet then it is usually preferred to rely on the APIs the
Sun JRE provides thus if the applet is to be run with Sun 1.4 then you
could use the W3C DOM Level 2 with methods like getElementsByTagName,
getElementsByTagNameNS, getChildNodes(), XPath is not supported then.
If you know your customers will have Sun 1.5 then as said you have W3C
DOM Level 3 and you have the Sun XPath API in javax.xml.xpath.*.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top