CoreOffice / XMLCoder

Easy XML parsing using Codable protocols in Swift
https://coreoffice.github.io/XMLCoder/
MIT License
795 stars 107 forks source link

" in XML element may not always be escaping #187

Closed owenzhao closed 4 years ago

owenzhao commented 4 years ago

In xliff exported by Xcode, most of the time there is a note element, like this

<note>Class = "NSTextFieldCell"; title = "Table View Cell"; ObjectID = "2Mq-0d-Xix";</note>

When decoded and encoded by XMLCoder, the "s in the element's value are escaping.

<note>Class = &quot;NSTextFieldCell&quot;; title = &quot;Table View Cell&quot;; ObjectID = &quot;2Mq-0d-Xix&quot;;</note>

Both are accepted by Xcode. Just the latter is not as clear as the prior in raw format for human reading.

MaxDesiatov commented 4 years ago

With the new API in master you can do something like this:

let encoder = XMLEncoder()
encoder.charactersEscapedInElements = [
        ("&", "&amp;"),
        ("<", "&lt;"),
        (">", "&gt;"),
        ("'", "&apos;"),
    ]

This will disable the &quot; substitution, but preserve the rest of the default ones.