Re: Cannot get nsIDOMDocument

Javier Pedemonte <[email protected]> Thu, 14 Jun 2007 17:09:24 -0500
Newsgroups gmane.comp.mozilla.devel.java
Message-ID <mrmdnWnqlb8DIezbnZ2dnUVZ_vShnZ2d__35380.4818158553$1181859024$gmane$org@mozilla.org>
Carfield Yim wrote:
> I try to get the DOM tree using following code:
> 
> 
> 					Mozilla.getInstance().initialize(new File("c:\\tools\
> \xulrunner"));
> 					final nsIWebBrowser webBrowser = (nsIWebBrowser)
> browser.getWebBrowser();
> 					final nsIDOMWindow contentDOMWindow = webBrowser
> 							.getContentDOMWindow();
> 					final nsIDOMDocument doc = contentDOMWindow.getDocument();
> 					System.out.println(doc);

You haven't called initEmbedding(), you haven't set up the window to 
draw into, you haven't loaded a page.  Basically, you need to do more 
than what you have here.

Take a look at the ATF implementation (embeds XULRunner in an Java SWT 
app): 
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.atf/components/plugins/org.eclipse.atf.mozilla.swt.browser/src/org/eclipse/swt/browser/MozillaBrowser.java?root=WebTools_Project&view=markup, 
starting with the MozillaBrowser contructor, which sets everything up.

The MozillaHelper.getMozillaInstance() call is what actually calls 
initialize() and initEmbedding(), as seen here: 
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.atf/components/plugins/org.eclipse.atf.mozilla.ide.core/src/org/eclipse/atf/mozilla/ide/core/MozillaHelper.java?revision=1.6&root=WebTools_Project&view=markup

Once you've set everything up as shown, you should be able to call 
getContentDOMWindow().


javier pedemonte