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

com.gitlab.mvysny.konsumexml.stax.DebugStaxParser.kt Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
package com.gitlab.mvysny.konsumexml.stax

/**
 * A parser which dumps everything it reads to stdout. Example of usage:
 * ```
 * val xml: String = "..."
 * val parser: StaxParser = DebugStaxParser(StaxParserFactory.create(xml.byteInputStream(), systemId))
 * val konsumer = Konsumer(StaxReader(parser), null, KonsumerSettings())
 * ...
 * ```
 * @author mavi
 */
class DebugStaxParser(val delegate: StaxParser) : StaxParser by delegate {
    override fun next() {
        delegate.next()
        when (eventType) {
            StaxEventType.CData -> println("")
            StaxEventType.Characters -> println(text)
            StaxEventType.Comment -> println("")
            StaxEventType.EndElement -> println("")
            StaxEventType.ProcessingInstruction -> println("")
            StaxEventType.StartElement -> println("<$elementName>")
            else -> println(eventType)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy