This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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: 12769
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: 18541

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?