CoreOffice / XMLCoder

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

CData gets ignored #190

Open KaiTeuber opened 4 years ago

KaiTeuber commented 4 years ago

Hi, I'm trying to parse the following XML: <Model int="123" bool="true"> <![CDATA[string]> </Model>

Into this struct: struct Model: Codable { let string: String let int: Int let bool: Bool enum CodingKeys: String, CodingKey { case int case bool case string = "" } }

But string stays empty. If I replace <![CDATA[string]> with string all things work as expected.

KaiTeuber commented 4 years ago

If I change CodingKey enum to enum CodingKeys: String, CodingKey { case int case bool case string = "#CDATA" } } value gets read.

bwetherfield commented 4 years ago

Glad you found a workaround here! Do you get the expected behavior with <![CDATA[string]]> (extra ]) ? Or is there still an issue

KaiTeuber commented 4 years ago

same behavior with the extra ] - if I use "#CDATA" as coding key it works too

dmitrymazo commented 3 years ago

It doesn't look like an error, it's just undocumented. @MaxDesiatov, please add an example to the Readme. Thanks. P.S.: cool project!

johankool commented 1 year ago

FYI, I am pretty sure this was fixed with https://github.com/CoreOffice/XMLCoder/pull/261