Re: can not get nsidomdocument from html file using mozilla browser instance
New <[email protected]> Tue, 9 Sep 2008 08:37:50 -0700 (PDT)
| Newsgroups | gmane.comp.mozilla.devel.java |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <7e3c8588-cf2e-429e-b444-cd3f52e7eb81__32076.5413962819$1220974973$gmane$org@x35g2000hsb.googlegroups.com> |
On Sep 5, 9:26 am, "Grant Gayed" <[email protected]> wrote: > Are you just asking about the "while (!shell.isDisposed())" ? If so, then > change it to something like "while (!completed)", and set "completed" to > true wherever appropriate (eg.- after the tags have been written to stdout). > Your code worked for me once I did this and uncommented some of its lines. > > If this is not what you were asking then please clarify what is not working > for you in the context of eclipse. > > Grant > > "New" <[email protected]> wrote in message > > news:f6955c18-5579-417d-95c0-8a00386de95c@v16g2000prc.googlegroups.com... > > > > > The following java works as java appliation. It spits out all tags in > > the HTML file. When I integrate the app with eclipse application, the > > app does not pass the while loop. Does anybody provide me a sample > > code to get nsIDOMDocument from HTML file using Mozilla browser > > instance. > > > public class TestSwtBrowser { > > public static void main(String[] args) { > > > //Display display = new Display(); > > Display display = Display.getDefault(); > > final Shell shell = new Shell(display); > > //final Shell shell = new Shell(); > > final Browser browser; > > > browser = new Browser(shell, SWT.MOZILLA); > > > if (browser.setUrl("C:\\eclipse\\eclipse\\TestHtml\\html\ > > \forms_e.html")) { > > > browser.addProgressListener(new ProgressListener() { > > public void changed(ProgressEvent event) { > > //Browser browser = (Browser)event.getSource(); > > nsIWebBrowser webBrowser = > > (nsIWebBrowser)browser.getWebBrowser(); > > if (webBrowser == null) { > > System.out.println("Could not get the nsIWebBrowser > > from the Browser widget"); > > > } > > nsIDOMWindow window = webBrowser.getContentDOMWindow(); > > nsIDOMDocument document = window.getDocument(); > > > //nsIDOMDocument document = browser.getDocument(); > > > System.out.println(document); > > //recursive call for displaying all children > > System.out.println("before recursive call for displaying > > all children"); > > > nsIDOMNode fNode = ((nsIDOMNode) document).getFirstChild(); > > System.out.println("First Node="+fNode.getNodeName()); > > displayAllChildren(fNode); > > nsIDOMNode lNode = ((nsIDOMNode) document).getLastChild(); > > System.out.println("Last Node="+lNode.getNodeName()); > > System.out.println("after recursive call for displaying all > > children"); > > } > > > public void completed(ProgressEvent event) { > > /* nsIWebBrowser webBrowser = > > (nsIWebBrowser)browser.getWebBrowser(); > > if (webBrowser == null) { > > System.out.println("Could not get the nsIWebBrowser > > from the Browser widget"); > > > } > > nsIDOMWindow window = webBrowser.getContentDOMWindow(); > > nsIDOMDocument document = window.getDocument(); > > > //nsIDOMDocument document = browser.getDocument(); > > > System.out.println(document);*/ > > > //nsIDOMElement rootElement = > > document.getDocumentElement(); > > //printElement(rootElement); > > } > > } ); > > > } > > > while (!shell.isDisposed()) { > > if (!display.readAndDispatch()) { > > display.sleep(); > > } > > } > > display.dispose(); > > > } > > > private static void displayAllChildren(nsIDOMNode node) { > > nsIDOMNodeList nsiNodelist = node.getChildNodes(); > > long size = nsiNodelist.getLength(); > > for (long c = 0; c < size; ++c) { > > nsIDOMNode child = nsiNodelist.item(c); > > System.out.println("tagName="+child.getNodeName()); > > if (child.hasChildNodes()) { > > displayAllChildren(child); > > } > > } > > }- Hide quoted text - > > - Show quoted text - I did not clearly expalain my problem. My concern is when the displaly disposes, the nsIDOMDocument loses the referrence. Looks like nsiDOMdocument is tied to the display of mozilla instance..if I want to do manipulation of the nsidomdocuement, i have to write logic in either completed or changed event . Now my problem has been resolved. Thanks grant.