😘
Xoxo Xoxo is a simple wrapper around org.w3c.dom to parse XML using nice Kotlin APIs. No more NodeList
, .item()
, etc... just use .children
, .filterIsInstance<>()
and all the Okio and Kotlin APIs we all love
Xoxo is designed for dynamic parsing in small JVM-only projects like Kotlin scripts and does not pretend to cover the full XML specification nor XML editing.
Installation
@file:DependsOn("net.mbonnin.xoxo:xoxo:0.2")
tag in a HTML file
File("index.html").toXmlDocument()
.root
.childElements
.first { it.name == "body" }
.childElements
.first { it.name == "div" }
.textContent
Find all elements with a "videoId" attribute and display their duration
-
30:30
-
31:00
""".trimIndent()
xmlString.toXmlDocument()
.root
.walkElements()
.filter { it.attributes.containsKey("videoId") }
.forEach {
println(it.attributes["title"])
println("duration:" + it.childElements.single().textContent)
}">
val xmlString = """
30:30
31:00
""".trimIndent()
xmlString.toXmlDocument()
.root
.walkElements()
.filter { it.attributes.containsKey("videoId") }
.forEach {
println(it.attributes["title"])
println("duration:" + it.childElements.single().textContent)
}
Read the text content of the first File("index.html").toXmlDocument()
.root
.childElements
.first { it.name == "body" }
.childElements
.first { it.name == "div" }
.textContent
Find all elements with a "videoId" attribute and display their duration
val xmlString = """
30:30
31:00
""".trimIndent()
xmlString.toXmlDocument()
.root
.walkElements()
.filter { it.attributes.containsKey("videoId") }
.forEach {
println(it.attributes["title"])
println("duration:" + it.childElements.single().textContent)
}