开发者

How to access CSS properties for a DOM node using the Cobra/Lobo HTML renderer

I am trying figure out how to access CSS properties for a DOM node (in this example <img> nodes) using the Cobra/Lobo toolkit. What I have at the moment is:

    UserAgentContext uacontext = new SimpleUserAgentContext();
    DocumentBuilderImpl builder = new DocumentBuilderImpl(uacontext);

    URL url = new URL(TEST_URI);
    InputStream in = url.openConnection().getInputStream();

    Reader reader = new InputStreamReader(in, "ISO-8859-1");
    InputSourceImpl inputSource = new Input开发者_如何转开发SourceImpl(reader, TEST_URI);
    HTMLDocumentImpl d = (HTMLDocumentImpl) builder.parse(inputSource);
    HTMLCollection images = d.getImages();

    for (int i = 0; i < images.getLength(); i++) {

        HTMLElementImpl n = (HTMLElementImpl) images.item(i);
        AbstractCSS2Properties curr = n.getCurrentStyle();

        System.out.println("Image " + i + ": " + curr.getPropertyValue("background-color"));
    }

Now this only seems to give me directly set styles - not inherited or computed styles. How can I get these as well?

Thanks


I expect you need to use the getComputedStyle method of Class HTMLElementImpl.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜