Example usage for org.jsoup.nodes Element dataNodes

List of usage examples for org.jsoup.nodes Element dataNodes

Introduction

In this page you can find the example usage for org.jsoup.nodes Element dataNodes.

Prototype

public List<DataNode> dataNodes() 

Source Link

Document

Get this element's child data nodes.

Usage

From source file:fr.isen.browser5.Util.UrlLoader.java

public void getScripts() {
    Elements scriptElements = doc.getElementsByTag("script");
    for (Element element : scriptElements) {
        for (DataNode node : element.dataNodes()) {
            script += node.getWholeData();
        }/*from  ww  w .  j av a 2s.c o  m*/
    }
}

From source file:psef.handler.HTMLFilter.java

/**
 * Revise all "style" statements with @import directives
 * @param doc the DOM document//from  w w w .ja  v a  2s.  co m
 * @throws PsefException 
 */
private void filterStyles(Document doc) throws PsefException {
    try {
        Elements styles = doc.getElementsByTag("style");
        for (Element style : styles) {
            List<DataNode> data = style.dataNodes();
            String styleText = "";
            StringBuilder sb = new StringBuilder();
            for (DataNode node : data) {
                styleText = node.getWholeData();
                int pos = readAtImport(styleText);
                while (pos > 0) {
                    sb.append("@import ");
                    styleText = styleText.substring(pos);
                    CSSUrl cssu = new CSSUrl(styleText);
                    styleText = styleText.substring(cssu.getPos());
                    cssu.revise(host, base + relPath, "styles");
                    URL u = new URL(cssu.getUrl(host, base + relPath));
                    downloadResource(u, cssu.getLocalPath());
                    sb.append(cssu.toString());
                    sb.append("\n");
                    pos = readAtImport(styleText);
                }
                node.setWholeData(sb.toString());
            }
            sb.append(styleText);
            //style.( sb.toString() );
        }
    } catch (Exception e) {
        throw new PsefException(e);
    }
}