XMLParsing
XMLParsing copied to clipboard
Issue parsing XML with attributes and a string value
<SomeElement SomeAttribute="value">some string value</SomeElement>
ends up only decoding as a string. I would expect to be able to have a struct like:
struct SomeElement: Codable {
let value: String
let attribute: String
enum CodingKeys: String, CodingKey {
case value = "#text"
case attribute = "SomeAttribute"
}
}
I receive the following error:
"Expected to decode Array<Any> but found a string/data instead."
My xml is structured like this:
<ParentElement>
<SomeElement SomeAttribute="value">some string value</SomeElement>
<SomeElement SomeAttribute="value">some other string value</SomeElement>
</ParentElement>
And my struct is:
struct ParentElement: Codable {
let someElements: [SomeElement]
enum CodingKeys: String, CodingKey {
case someElements = "SomeElement"
}
}
struct SomeElement: Codable {
let someAttribute: String
let value: String
enum CodingKeys: String, CodingKey {
case someAttribute = "SomeAttribute"
case value = "??"
}
}
Please, any solution to this?!
Any solution for this ?
This library is apparently no longer maintained. The issue is fixed in my XMLCoder fork with the coding key value intrinsic feature.