Java HTML Jsoup Document normalizeWhitespaces(Document doc)

Here you can find the source of normalizeWhitespaces(Document doc)

Description

Normalizes the whitespaces in text nodes of the specified document.

License

Open Source License

Parameter

Parameter Description
doc The document to normalise whitespaces in.

Return

The normalized document.

Declaration

private static Document normalizeWhitespaces(Document doc) 

Method Source Code

//package com.java2s;
/*//ww  w. ja v  a2s .  c  om
 * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
 * See LICENSE.md for licensing information.
 */

import org.jsoup.nodes.Document;

import org.jsoup.nodes.TextNode;

public class Main {
    /**
     * Normalizes the whitespaces in text nodes of the specified document.
     * Normally this is done by pretty printing but I disabled it because
     * indentation done by Jsoup is pretty buggy. So I have to normalize the
     * whitespaces manually here.
     * 
     * @param doc
     *            The document to normalise whitespaces in.
     * @return The normalized document.
     */
    private static Document normalizeWhitespaces(Document doc) {
        for (TextNode node : doc.body().textNodes()) {
            node.text(node.text());
        }
        return doc;
    }
}

Related

  1. getLoginFields(Document doc)
  2. getTextFromAvailableDivID(Document doc, String divID)
  3. getTitleFromDocument(Document doc)
  4. keepLineBreak(Document docRes)
  5. makeAbsolute(Document doc)
  6. postDocument(String url, Collection data)
  7. removeTag(Document doc, String selector)
  8. retrieveHiddenInputs(Document doc)
  9. saveDocumentToDirectory(final org.jsoup.nodes.Document doc, final String fileName, final Path tmpDir)