pdvrieze / xmlutil

XML Serialization library for Kotlin
https://pdvrieze.github.io/xmlutil/
Apache License 2.0
363 stars 30 forks source link

Comments in XML will cause native DOM parser to fail #189

Closed StefanOltmann closed 7 months ago

StefanOltmann commented 7 months ago

I'm working on an improvement for https://github.com/Ashampoo/xmpcore where I want it to be more resilient about real-world malformed XMP in some of the Unsplash test images I use to test Ashampoo Photos.

This file can be read on Java, but it fails on the iOS target: sample_50.xmp.txt

Here is the code used to read the file: https://github.com/Ashampoo/xmpcore/blob/2815304b1a802c37ec4ac2e9fcd16de242680dec/src/commonMain/kotlin/com/ashampoo/xmp/DomParser.kt#L11

The error says Attempting to add node 8 where not permitted.

The problem with the file is that some fields are repeated. My new code now ignores repeated fields and always takes the first. That may be better than not reading the XMP at all.

Can I somehow configure the parser to skip/ignore such errors, so that I can handle/correct them in the steps after that?

StefanOltmann commented 7 months ago

I identified the primary issue to be related to the comment in the sample file. The comment was added by me for documentation purposes and was not part of the original file.

Fortunately, this issue is not significant. I believe your implementation could simply skip comment blocks instead of encountering a failure, which should resolve the issue satisfactorily.

pdvrieze commented 7 months ago

I've found the problem. I've made the platform independent document implementation allow comments outside the document element.