Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue parsing XML with attributes and a string value #5

Open
ciauri opened this issue Mar 15, 2018 · 3 comments
Open

Issue parsing XML with attributes and a string value #5

ciauri opened this issue Mar 15, 2018 · 3 comments

Comments

@ciauri
Copy link

ciauri commented Mar 15, 2018

<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 = "??"
    }
}
ciauri added a commit to ciauri/XMLParsing that referenced this issue Mar 15, 2018
- In the presence of attributes and child elements, chardata values will be keyed on a custom value provided by the user via the new property `characterDataToken ` on the XMLDecoder
ciauri added a commit to ciauri/XMLParsing that referenced this issue May 18, 2018
- In the presence of attributes and child elements, chardata values will be keyed on a custom value provided by the user via the new property `characterDataToken ` on the XMLDecoder
@robiscjuan
Copy link

Please, any solution to this?!

@ThePredators
Copy link

Any solution for this ?

@MaxDesiatov
Copy link

MaxDesiatov commented Oct 19, 2021

This library is apparently no longer maintained. The issue is fixed in my XMLCoder fork with the coding key value intrinsic feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants