Skip to content

Commit

Permalink
Use xmlStreaming API (#31)
Browse files Browse the repository at this point in the history
use xmlStreaming
  • Loading branch information
StefanOltmann authored Aug 27, 2024
1 parent d4c4ce9 commit 45f0970
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/commonMain/kotlin/com/ashampoo/xmp/internal/DomParser.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.ashampoo.xmp.internal

import com.ashampoo.xmp.XMPException
import nl.adaptivity.xmlutil.DomWriter
import nl.adaptivity.xmlutil.EventType
import nl.adaptivity.xmlutil.ExperimentalXmlUtilApi
import nl.adaptivity.xmlutil.XmlUtilInternal
import nl.adaptivity.xmlutil.dom2.Document
import nl.adaptivity.xmlutil.writeCurrent
Expand All @@ -12,7 +12,7 @@ internal object DomParser {

private const val RDF_RDF_END = "</rdf:RDF>"

@OptIn(XmlUtilInternal::class)
@OptIn(XmlUtilInternal::class, ExperimentalXmlUtilApi::class)
fun parseDocumentFromString(input: String): Document {

/*
Expand All @@ -37,7 +37,9 @@ internal object DomParser {

try {

val writer = DomWriter()
val document = xmlStreaming.genericDomImplementation.createDocument()

val writer = xmlStreaming.newWriter(document)

val reader = xmlStreaming.newReader(trimmedInput)

Expand All @@ -46,7 +48,7 @@ internal object DomParser {
reader.writeCurrent(writer)
} while (event != EventType.END_DOCUMENT)

return writer.target
return document

} catch (ex: Exception) {
throw XMPException("Error reading the XML file: ${ex.message}", XMPErrorConst.BADSTREAM, ex)
Expand Down

0 comments on commit 45f0970

Please sign in to comment.