XMLCoder icon indicating copy to clipboard operation
XMLCoder copied to clipboard

CData gets ignored

Open KaiTeuber opened this issue 4 years ago • 5 comments

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 avatar Jun 03 '20 13:06 KaiTeuber

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

KaiTeuber avatar Jun 03 '20 19:06 KaiTeuber

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

bwetherfield avatar Jun 03 '20 21:06 bwetherfield

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

KaiTeuber avatar Jul 09 '20 21:07 KaiTeuber

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

dmitrymazo avatar Jan 29 '21 16:01 dmitrymazo

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

johankool avatar Apr 13 '23 07:04 johankool