All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.moe.tlaster.ktml.dom.Node.kt Maven / Gradle / Ivy

There is a newer version: 0.0.7
Show newest version
package moe.tlaster.ktml.dom

sealed interface Node {
    val name: String
}

data class Element(
    override val name: String,
    val namespace: String = "",
    val parent: Element? = null,
) : Node {
    val attributes = linkedMapOf()
    val children = arrayListOf()
    val innerText: String
        get() = children.joinToString("") {
            when (it) {
                is Text -> it.text
                is Element -> it.innerText
                else -> ""
            }
        }
}

data class Text(
    val text: String,
    override val name: String = "#text",
) : Node {
    override fun toString(): String {
        return text
    }
}

data class Comment(
    val text: String,
    override val name: String = "#comment",
) : Node {
    override fun toString(): String {
        return ""
    }
}

data class Doctype(
    override val name: String,
) : Node {
    override fun toString(): String {
        return ""
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy