File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes DOM of current page? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "DOM of current page?" Watch "DOM of current page?" New topic

DOM of current page?

S. Schaefer

Joined: Feb 06, 2011
Posts: 7

Hi there.

I was just wondering if there is a way to get the DOM of the currently loaded page for example to a org.jdom.document or something like this,
so that i can get a specific node using xpath or something similar and then get the child-element of that node...?
I found HtmlUnit while "googling" (does that word even exist in english? :P), but i'm not quite sure that it does what i'm looking for ...

Looking forward to your answers and thanks in advance
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Current page in what?

Assuming we are talking about a HTML page, what loaded it?

If the page was coded as XHTML it can be parsed into a DOM by normal XML parsers but if was generated as HTML 4 it probably is not valid XML.

S. Schaefer

Joined: Feb 06, 2011
Posts: 7

The current page shown in the firefox webbrowser ;-)
Is should have been coded in xhtml, but rendered by icefaces ... don't know if this has something to say ... ;D
So it should be XMLParser-usable ... but how does the parser get the currently rendered page?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Sure, you can access the page's DOM via Javascript. But you seem to be asking about Java. Should we assume your question involves an applet? You didn't say anything like that.
S. Schaefer

Joined: Feb 06, 2011
Posts: 7

I thought i said something like that, i'm sorry ;-)

But your answer helped me nevertheless...
At least i got what i was looking for by using xpath ;-)
I agree. Here's the link:
subject: DOM of current page?
It's not a secret anymore!