commonMain.com.fleeksoft.ksoup.nodes.DataNode.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ksoup-jvm Show documentation
Show all versions of ksoup-jvm Show documentation
Ksoup is a Kotlin Multiplatform library for working with HTML and XML, and offers an easy-to-use API for URL fetching, data parsing, extraction, and manipulation using DOM and CSS selectors.
The newest version!
package com.fleeksoft.ksoup.nodes
import okio.IOException
/**
* Create a new DataNode.
* A data node, for contents of style, script tags etc, where contents should not show in text().
*
* @param data data contents
*/
public class DataNode(data: String) : LeafNode() {
init {
value = data
}
override fun nodeName(): String {
return "#data"
}
public fun getWholeData(): String = coreValue()
/**
* Set the data contents of this node.
* @param data unencoded data
* @return this node, for chaining
*/
public fun setWholeData(data: String?): DataNode {
coreValue(data)
return this
}
@Throws(IOException::class)
override fun outerHtmlHead(
accum: Appendable,
depth: Int,
out: Document.OutputSettings,
) {
/* For XML output, escape the DataNode in a CData section. The data may contain pseudo-CData content if it was
parsed as HTML, so don't double up Cdata. Output in polygot HTML / XHTML / XML format. */
val data = getWholeData()
if (out.syntax() === Document.OutputSettings.Syntax.xml && !data.contains("")
} else if (parentNameIs("style")) {
accum.append("/**/")
} else {
accum.append("")
}
} else {
// In HTML, data is not escaped in the output of data nodes, so < and & in script, style is OK
accum.append(getWholeData())
}
}
override fun outerHtmlTail(
accum: Appendable,
depth: Int,
out: Document.OutputSettings,
) {
}
override fun toString(): String {
return outerHtml()
}
override fun createClone(): Node {
return DataNode(value as String)
}
override fun clone(): DataNode {
return super.clone() as DataNode
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy