Skip to content

Parser uses only fractions of strings/names and throws away the rest (annotation.title) #2

@GerdC

Description

@GerdC

How to test:
take a kml file with a place mark with a name that contains an unusual character:

Heiglhofstraße 1-3

What happens:
the final annotation has a title == "ße 1-3"

What is expected:
the final annotation has a title == "Heiglhofstraße 1-3"

Cause:
Any XML SAX parser is allowed to divide strings into chunks and present the chunks as separate callbacks to method parser(_ parser: XMLParser, foundCharacters string: String).
SAX Parsers are not only allowed to do this, most parsers actually do this and so is Apples implementation.

In our case, parser(_ parser: XMLParser, foundCharacters string: String) is called twice:
once with string "Heiglhofstra" and once with "ße 1-3"
The current implementation throws away the first string when assigning the annotation title.

partial fix for my test case (this is a dirty hack, see comment below):
case .some(.name):
if let oldKmlStr = kmlObjectLookup[.name] as? KMLStringValue {
let value = oldKmlStr.value + string
kmlObjectLookup[.name] = KMLStringValue(value: value)
} else {
kmlObjectLookup[.name] = KMLStringValue(value: string)
}
(be aware that I removed the where condition which is also a bug - probably your first attempt to fix the problem)

The same bug appears probably here
case .some(.description):
kmlObjectLookup[.description] = KMLStringValue(value: string)
But this is not relevant for my data.

Usually what I do when implementing a SAX parser, is collecting all the string fragments.
At endElement I look if there is some collected string data and call a method that looks like your parser(_ parser: XMLParser, foundCharacters string: String) implementation. This would be the good solution, not my quick hack above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions