added a Node.clear() helper method so they can be cleared like collections

This commit is contained in:
James Strachan
2012-07-20 12:12:45 +01:00
parent 2a3ffed228
commit a2184526d8
+11 -1
View File
@@ -246,7 +246,17 @@ class ElementListAsList(val nodeList: NodeList): AbstractList<Element>() {
}
/** Removes all the children from this node */
fun Node.clear(): Unit {
while (true) {
val child = firstChild
if (child == null) {
return
} else {
removeChild(child)
}
}
}
/** Returns an [[Iterator]] over the next siblings of this node */
fun Node.nextSiblings() : Iterator<Node> = NextSiblingIterator(this)