com.gitlab.mvysny.konsumexml.stax.EntityExpandingStaxParser.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
/**
* Expands [StaxEventType.EntityReference] with known text contents (such as character entities);
* if the entity contents is not known the entity reference is left as-is.
*/
class EntityExpandingStaxParser(val delegate: StaxParser) : StaxParser by delegate {
override val eventType: StaxEventType
get() {
val e = delegate.eventType
if (e == StaxEventType.EntityReference && text != null) {
// both the entity text and characters can be retrieved via the `text` property
// so it's enough if we just pretend we've received Characters instead of an EntityRef
return StaxEventType.Characters
}
return e
}
}