added attribute lookup helper method

This commit is contained in:
James Strachan
2012-02-24 17:54:03 +00:00
parent 5841438134
commit 7f97f9710e
2 changed files with 6 additions and 0 deletions
+5
View File
@@ -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()
+1
View File
@@ -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")
}