aral
1.0.1indexedLightweight, efficient library for XML parsing with a simple, flow-based API, enabling asynchronous handling of XML parsing events. Offers write-once, run-anywhere functionality without heavy dependencies.
Lightweight, efficient library for XML parsing with a simple, flow-based API, enabling asynchronous handling of XML parsing events. Offers write-once, run-anywhere functionality without heavy dependencies.
aral is a lightweight, efficient Kotlin Multiplatform library for XML parsing. Built for the modern, multi-platform world, it offers a simple, flow-based API for parsing XML documents across Android, JVM, iOS, macOS, watchOS, and tvOS.
aral is available on Maven Central.
Add Maven Central to your settings.gradle.kts or build.gradle.kts file if it's not already there:
repositories {
mavenCentral()
}
Add the dependency to your commonMain source set:
The entry point to the library is the XMLParser. You can easily get an instance of it in your common code.
XMLParserimport it.calogerosanfilippo.aral.xml.XMLParserFactory
val xmlParser = XMLParserFactory.getParser()
The parse method takes an XML string and returns a Flow of XMLParserEvents. You can then collect the flow to handle each event.
The XMLParserEvent is a sealed class that represents all possible events during parsing:
Copyright 2024-2026 Calogero Sanfilippo
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this except compliance the License.
You may obtain a copy of the License at
http:
Unless applicable law agreed to writing, software
distributed under the License distributed an BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
See the License the specific language governing permissions
limitations under the License.
commonMain {
dependencies {
implementation("it.calogerosanfilippo:aral:<latest-version>")
}
}
import it.calogerosanfilippo.aral.xml.XMLParserEvent
import kotlinx.coroutines.flow.collect
val xmlString = """
<root>
<item id="1">Hello</item>
<item id="2">World</item>
</root>
"""
val eventFlow = xmlParser.parse(xmlString)
eventFlow.collect { event ->
when (event) {
is XMLParserEvent.DocumentStart -> println("Document parsing started")
is XMLParserEvent.DocumentEnd -> println("Document parsing finished")
is XMLParserEvent.ElementStartFound -> println("Element started: ${event.name}, attributes: ${event.attributes}")
is XMLParserEvent.ElementEndFound -> println("Element ended: ${event.name}")
is XMLParserEvent.CharactersFound -> println("Characters found: ${event.characters}")
is XMLParserEvent.Error -> println("An error occurred: ${event.exception}")
}
}
sealed class XMLParserEvent {
data object DocumentStart : XMLParserEvent()
data object DocumentEnd : XMLParserEvent()
data class ElementStartFound(val name: String, val namespaceURI: String?, val localName: String, val attributes: Map<String, String>) : XMLParserEvent()
data class ElementEndFound(val name: String, val namespaceURI: String?, val localName: String) : XMLParserEvent()
data class CharactersFound(val characters: String) : XMLParserEvent()
data class Error(val exception: Exception) : XMLParserEvent()
}
Surfaced from shared tags and platforms — no rankings paid for.