XpathAPI selectSingleNode in XHTML document returning NULL

A

anupamjain

Tired, Exhausted, searched the web, usenets,forums thorughly but still
clueless. I guess it's time to post on the group :

This is the issue I have been trying to resolve since today morning :

I have an XHTML document in string form which I parse using Xerces
DOMParser (using an InputSource to read it).

Now I am trying to get to a node for which I have the Xpath, using the
XPathAPI.

So something like this :

Document doc = parser.getDocument(); // where parser is an instance
of DOMParser
Node onenode =
XPathAPI.selectSingleNode(doc,"html/body",doc.getDocumentElement());

I am using doc.getDocumentElement() as the namespace node because the
namespace is declared there - <html
xmlns="http://ww.w3.org/1999/xhtml">

The problem : selectSingleNode is always returning NULL.

I have tried almost everything. I saw somewhere on the groups that
somebody had set the Namespaceaware(boolean) to true for DomFactory but
I am not using DOMFactory. I am using DOMParser and I tried
setNamespaces(boolean) but it cannot find the method (I wonder why -
when it's a derived class from XMLParser).

Anyways, thats the problem I have been dealing with since today morning
(read as 8 hours).

If you have a solution, please help !

Thanks,
Anupam
 
A

anupamjain

Sorry, I was looking at the cached page I guess. Just saw the two
replies.

- Anupam
 
C

Chris Smith

Document doc = parser.getDocument(); // where parser is an instance
of DOMParser
Node onenode =
XPathAPI.selectSingleNode(doc,"html/body",doc.getDocumentElement());

I don't know this XPathAPI class very well. (Are you using Java 1.5?
If so, any reason you're not using XPath from the standard API?)

However, it looks like you're looking for a child of the document
element called "html". Rather, "html" IS the document element. Try
either of the following instead, and see one or both of them work
better.

XPathAPI.selectSingleNode(doc,"/html/body",doc.getDocumentElement());
XPathAPI.selectSingleNode(doc,"html/body",doc);

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top