Skip to content
Snippets Groups Projects
Commit 35554b3f authored by Kaj Koivunen's avatar Kaj Koivunen :coffee:
Browse files

XML: value -> content

parent d9947f89
No related branches found
No related tags found
No related merge requests found
......@@ -78,7 +78,7 @@ class DictionaryParser {
}
}
element("literal") {
start { character!!.literal = value()!! }
start { character!!.literal = content()!! }
}
element("reading_meaning") {
start { rmgroup = RMGroup() }
......@@ -91,7 +91,7 @@ class DictionaryParser {
start {
rmgroup!!.meaning.add(Pair(
attribute("m_lang"),
value()!!
content()!!
))
}
}
......@@ -99,7 +99,7 @@ class DictionaryParser {
start {
rmgroup!!.reading.add(Pair(
attribute("r_type"),
value()!!
content()!!
))
}
}
......
......@@ -44,11 +44,19 @@ class XMLParser private constructor(path: String) {
@DSL
inner class Element(private val name: String, private val reader: XMLEventReader, private val event: XMLEvent) {
/**
* Specify code to execute when encountering a starting tag of the specified element
* @param f code to execute
*/
fun start(f: StartElement.() -> Unit) {
if (event.isStartElement && event.asStartElement().name.localPart.toString() == name)
StartElement(reader, event.asStartElement()).f()
}
/**
* Specify code to execute when encountering a closing tag of the specified element
* @param f code to execute
*/
fun end(f: () -> Unit) {
if (event.isEndElement && event.asEndElement().name.localPart.toString() == name)
f()
......@@ -56,7 +64,10 @@ class XMLParser private constructor(path: String) {
@DSL
inner class StartElement(private val reader: XMLEventReader, private val event: javax.xml.stream.events.StartElement) {
fun value(): String? {
/**
* Get the content of the current element
*/
fun content(): String? {
return try {
reader.peek().asCharacters().data
} catch (e: ClassCastException) {
......@@ -64,6 +75,9 @@ class XMLParser private constructor(path: String) {
}
}
/**
*
*/
fun attribute(attr: String): String? = event.getAttributeByName(QName(attr))?.value
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment