@startuml
'https://plantuml.com/state-diagram
[*] --> Lists: start_CodeLists
Lists --> Codes: start_CodeList
Codes --> Name: start_Name
Name -> Read: cdata
Name -> Codes: end_Name
Codes --> Lists: end_CodeList
Lists --> [*]: end_CodeLists
@enduml
fun interface State {
fun eval(eventType: Int)
}
private var result = ""
private var current: State = start
fun main() {
while (reader.hasNext())
current.eval(reader.next())
print(result)
}
private val start: State = State {
when (it) {
XMLStreamReader.START_ELEMENT ->
if (reader.localName == "CodeLists")
current = lists
}
}
private val lists: State = State {
when (it) {
XMLStreamReader.START_ELEMENT ->
if (reader.localName == "CodeList")
current = codes
XMLStreamReader.END_ELEMENT ->
if (reader.localName == "CodeLists")
current = start
}
}
private val codes: State = State {
when (it) {
XMLStreamReader.START_ELEMENT ->
if (reader.localName == "Name")
result += reader.elementText + "\n"
XMLStreamReader.END_ELEMENT ->
if (reader.localName == "CodeList")
current = lists
}
}