org.jsoup.nodes.DataNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsoup Show documentation
Show all versions of jsoup Show documentation
jsoup is a Java library for working with real-world HTML. It provides a very convenient API for extracting and manipulating data, using the best of DOM, CSS, and jquery-like methods. jsoup implements the WHATWG HTML5 specification, and parses HTML to the same DOM as modern browsers do.
package org.jsoup.nodes;
import java.io.IOException;
/**
A data node, for contents of style, script tags etc, where contents should not show in text().
@author Jonathan Hedley, [email protected] */
public class DataNode extends LeafNode {
/**
Create a new DataNode.
@param data data contents
*/
public DataNode(String data) {
value = data;
}
public String nodeName() {
return "#data";
}
/**
Get the data contents of this node. Will be unescaped and with original new lines, space etc.
@return data
*/
public String getWholeData() {
return coreValue();
}
/**
* Set the data contents of this node.
* @param data unencoded data
* @return this node, for chaining
*/
public DataNode setWholeData(String data) {
coreValue(data);
return this;
}
void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException {
accum.append(getWholeData()); // data is not escaped in return from data nodes, so " in script, style is plain
}
void outerHtmlTail(Appendable accum, int depth, Document.OutputSettings out) {}
@Override
public String toString() {
return outerHtml();
}
@Override
public DataNode clone() {
return (DataNode) super.clone();
}
/**
Create a new DataNode from HTML encoded data.
@param encodedData encoded data
@param baseUri base URI
@return new DataNode
@deprecated Unused, and will be removed in 1.15.1.
*/
@Deprecated
public static DataNode createFromEncoded(String encodedData, String baseUri) {
String data = Entities.unescape(encodedData);
return new DataNode(data);
}
}