added more working DOM test cases for JS
This commit is contained in:
@@ -311,6 +311,25 @@ val NodeList?.last : Node?
|
||||
get() = this.tail
|
||||
|
||||
|
||||
/** Converts the node list to an XML String */
|
||||
fun NodeList?.toXmlString(xmlDeclaration: Boolean = false): String {
|
||||
return if (this == null)
|
||||
"" else {
|
||||
nodesToXmlString(this.toList(), xmlDeclaration)
|
||||
}
|
||||
}
|
||||
|
||||
/** Converts the collection of nodes to an XML String */
|
||||
public fun nodesToXmlString(nodes: java.lang.Iterable<Node>, xmlDeclaration: Boolean = false): String {
|
||||
// TODO this should work...
|
||||
// return this.map<Node,String>{it.toXmlString()}.makeString("")
|
||||
val builder = StringBuilder()
|
||||
for (n in nodes) {
|
||||
builder.append(n.toXmlString(xmlDeclaration))
|
||||
}
|
||||
return builder.toString().sure()
|
||||
}
|
||||
|
||||
// Syntax sugar
|
||||
|
||||
inline fun Node.plus(child: Node?): Node {
|
||||
@@ -381,7 +400,7 @@ Adds a newly created text node to an element which either already has an owner D
|
||||
*/
|
||||
fun Element.addText(text: String?, doc: Document? = null): Element {
|
||||
if (text != null) {
|
||||
val child = ownerDocument(doc).createTextNode(text)
|
||||
val child = this.ownerDocument(doc).createTextNode(text)
|
||||
this.appendChild(child)
|
||||
}
|
||||
return this
|
||||
|
||||
@@ -153,13 +153,6 @@ fun Element.removeClass(cssClass: String): Boolean {
|
||||
}
|
||||
|
||||
|
||||
/** Converts the node list to an XML String */
|
||||
fun NodeList?.toXmlString(xmlDeclaration: Boolean = false): String {
|
||||
return if (this == null)
|
||||
"" else {
|
||||
nodesToXmlString(this.toList(), xmlDeclaration)
|
||||
}
|
||||
}
|
||||
|
||||
/** Creates a new document with the given document builder*/
|
||||
public fun createDocument(builder: DocumentBuilder): Document {
|
||||
@@ -225,7 +218,10 @@ public fun createTransformer(source: Source? = null, factory: TransformerFactory
|
||||
}
|
||||
|
||||
/** Converts the node to an XML String */
|
||||
public fun Node.toXmlString(xmlDeclaration: Boolean = false): String {
|
||||
public fun Node.toXmlString(): String = toXmlString(false)
|
||||
|
||||
/** Converts the node to an XML String */
|
||||
public fun Node.toXmlString(xmlDeclaration: Boolean): String {
|
||||
val writer = StringWriter()
|
||||
writeXmlString(writer, xmlDeclaration)
|
||||
return writer.toString().sure()
|
||||
@@ -237,14 +233,3 @@ public fun Node.writeXmlString(writer: Writer, xmlDeclaration: Boolean): Unit {
|
||||
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, if (xmlDeclaration) "no" else "yes")
|
||||
transformer.transform(DOMSource(this), StreamResult(writer))
|
||||
}
|
||||
|
||||
/** Converts the collection of nodes to an XML String */
|
||||
public fun nodesToXmlString(nodes: java.lang.Iterable<Node>, xmlDeclaration: Boolean = false): String {
|
||||
// TODO this should work...
|
||||
// return this.map<Node,String>{it.toXmlString()}.makeString("")
|
||||
val builder = StringBuilder()
|
||||
for (n in nodes) {
|
||||
builder.append(n.toXmlString(xmlDeclaration))
|
||||
}
|
||||
return builder.toString().sure()
|
||||
}
|
||||
Reference in New Issue
Block a user