Skip to content

Commit

Permalink
chore: update XML parser to reflect XML structure and avoid temporari…
Browse files Browse the repository at this point in the history
…ly uninitialized variables
  • Loading branch information
cbeyls committed Dec 27, 2023
1 parent a03329b commit 0e08f3d
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions app/src/main/java/be/digitalia/fosdem/parsers/EventsParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,31 @@ class EventsParser @Inject constructor(
return sequence {
while (!parser.isEndDocument) {
if (parser.isStartTag("schedule")) {
var currentDay: Day? = null
var currentRoomName: String? = null

while (!parser.isNextEndTag("schedule")) {
if (parser.isStartTag) {
when (parser.name) {
"day" -> {
currentDay = Day(
index = parser.getAttributeValue(null, "index")!!.toInt(),
date = LocalDate.parse(parser.getAttributeValue(null, "date"))
val day = Day(
index = parser.getAttributeValue(null, "index")!!.toInt(),
date = LocalDate.parse(
parser.getAttributeValue(null, "date")
)
)

while (!parser.isNextEndTag("day")) {
if (parser.isStartTag("room")) {
val roomName: String? =
parser.getAttributeValue(null, "name")

while (!parser.isNextEndTag("room")) {
if (parser.isStartTag("event")) {
yield(parseEvent(parser, day, roomName))
}
}
}
}
}
"room" -> currentRoomName = parser.getAttributeValue(null, "name")
"event" -> yield(parseEvent(parser, currentDay!!, currentRoomName))

else -> parser.skipToEndTag()
}
}
Expand Down

0 comments on commit 0e08f3d

Please sign in to comment.