com.jtransc.serialization.xml.XmlExt.kt Maven / Gradle / Ivy
package com.jtransc.serialization.xml
import com.jtransc.vfs.SyncVfsFile
import org.intellij.lang.annotations.Language
fun Iterable.str(name: String, defaultValue: String = ""): String = this.first().attributes[name] ?: defaultValue
fun Iterable.children(name: String): Iterable = this.flatMap { it.children(name) }
val Iterable.allChildren: Iterable get() = this.flatMap(Xml::allChildren)
operator fun Iterable.get(name: String): Iterable = this.children(name)
fun String.toXml(): Xml = Xml.parse(this)
fun Xml(@Language("xml") str: String): Xml = Xml.parse(str)
/*suspend*/ fun SyncVfsFile.readXml(): Xml = Xml(this.readString())