added attribute lookup helper method
This commit is contained in:
@@ -95,6 +95,11 @@ fun Element.get(selector: String): List<Element> {
|
||||
return this.getElementsByTagName(selector).toElementList()
|
||||
}
|
||||
|
||||
/** Returns the attribute value or null if its not present */
|
||||
inline fun Element?.attribute(name: String): String? {
|
||||
return this?.getAttribute(name)
|
||||
}
|
||||
|
||||
/** Returns the children of the element as a list */
|
||||
inline fun Element?.children(): List<Node> {
|
||||
return this?.getChildNodes().toList()
|
||||
|
||||
@@ -35,6 +35,7 @@ class DomBuilderTest() : TestSupport() {
|
||||
if (grandChild != null) {
|
||||
println("got element ${grandChild.toXmlString()} with text '${grandChild.text}`")
|
||||
assertEquals("Hello World!", grandChild.text)
|
||||
assertEquals("tiny", grandChild.attribute("class") ?: "")
|
||||
} else {
|
||||
fail("Not an Element $grandChild")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user