com.gitlab.mvysny.konsumexml.stax.DebugStaxParser.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of konsume-xml Show documentation
Show all versions of konsume-xml Show documentation
Konsume-XML: A simple functional XML parser with no annotations
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("$elementName>")
StaxEventType.ProcessingInstruction -> println("$text?>")
StaxEventType.StartElement -> println("<$elementName>")
else -> println(eventType)
}
}
}