Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

XpathAPI selectSingleNode in XHTML document returning NULL

Thread view: 
anupamjain@gmail.com - 27 Mar 2006 03:39 GMT
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
anupamjain@gmail.com - 27 Mar 2006 17:25 GMT
I am still clueless about this. Can somebody please help me out?

- Anupam

> Tired, Exhausted, searched the web, usenets,forums thorughly but still
> clueless. I guess it's time to post on the group :
[quoted text clipped - 33 lines]
> Thanks,
> Anupam
anupamjain@gmail.com - 27 Mar 2006 17:27 GMT
Sorry, I was looking at the cached page I guess. Just saw the two
replies.

- Anupam
Chris Smith - 28 Mar 2006 07:16 GMT
> 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);

Signature

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.