I\'m using Jsoup for sanitizing user input from a form. The form in question contains a that expects plain text. When the form is submitted, I
For future generations, if you still need to get access to original text with whitespace, you can use TextNode.getWholeText() method.
Sample code:
/**
* @param cell element that contains whitespace formatting
* @return
*/
public static String getText(Element cell) {
String text = null;
List childNodes = cell.childNodes();
if (childNodes.size() > 0) {
Node childNode = childNodes.get(0);
if (childNode instanceof TextNode) {
text = ((TextNode)childNode).getWholeText();
}
}
if (text == null) {
text = cell.text();
}
return text;
}
In the code above, we assume that the passed in element contains text content directly inside element body (we take the first node). If that is not so, it will fall back to regular Element.text() method.