Re: can not get nsidomdocument from html file using mozilla browser instance
"Grant Gayed" <[email protected]> Fri, 5 Sep 2008 10:26:34 -0400
| Newsgroups | gmane.comp.mozilla.devel.java |
|---|---|
| Message-ID | <U4adnebnbMMG3FzVnZ2dnUVZ_sTinZ2d__859.244101639156$1220625165$gmane$org@mozilla.org> |
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); > } > } > }