Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use xmlStreaming API #31

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading