nsIDomDocument traversal help

faayil <[email protected]>
Newsgroups gmane.comp.mozilla.devel.java
Organization http://groups.google.com
Message-ID <1176849453.414321.120230__28091.4359180771$1176849810$gmane$org@o5g2000hsb.googlegroups.com>
Hi,
I am trying to use the MozillaBrowser from eclipse/atf. The following
code works but the dom traversal doesnt seem to work. Is there
something I am missing? Whats the best way to convert from the w3c dom
to the svg dom to get the coordinates?

Thanks.
Irfan

The output is always ...

=====

File grePath = /home/irfan/downloads/xulrunner/1.8.1.3/xulrunner
grePath.getPath = /home/irfan/downloads/xulrunner/1.8.1.3/xulrunner
org.mozilla.interfaces.nsIDOMDocument@18e3e60
HTML
null
HEAD
null
META
null
content
text/html; charset=UTF-8

=====

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.MozillaBrowser;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNamedNodeMap;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsIDOMNodeList;

public class TestSwtBrowser {
    public static void main(String[] args) throws Exception {
        Display display = new Display();
        final Shell shell = new Shell(display);

        final MozillaBrowser browser = new MozillaBrowser(shell,
SWT.BORDER);
        if (browser.setUrl("http://www.google.com/")) {
            browser.addProgressListener(new ProgressListener() {
                public void changed(ProgressEvent event) {
                }

                public void completed(ProgressEvent event) {
                    nsIDOMDocument document = browser.getDocument();

                    System.out.println(document);

                    nsIDOMElement rootElement =
document.getDocumentElement();
                    printElement(rootElement);
                }
            });
        }

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }

    private static void printElement(nsIDOMNode node) {
        System.out.println(node.getNodeName());
        System.out.println(node.getNodeValue());

        nsIDOMNamedNodeMap attributes = node.getAttributes();

        for (long i = 0, n1 = attributes.getLength(); n1 > 0; i++,
n1--) {
            nsIDOMNode child = attributes.item(i);
            printElement(child);
        }

        nsIDOMNodeList children = node.getChildNodes();

        for (long i = 0, n1 = children.getLength(); n1 > 0; i++, n1--)
{
            nsIDOMNode child = children.item(i);
            printElement(child);
        }
    }
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.