ShawnMoore / XMLParsing

XMLEncoder & XMLDecoder using the codable protocol in Swift 4.2
MIT License
332 stars 100 forks source link

Issue parsing Custom XML Structure #47

Open alexllao opened 5 years ago

alexllao commented 5 years ago

Hi!

I've this XML Structure:

<xml>
<response>
    <data>
        <modules>
            <module>
                <id>1</id>
            </module>
        </modules>
    </data>
    <result_id>1</result_id>
    <result_text></result_text>
    <timeout>207</timeout>
</response>
</xml>

And my code to Parse this:

struct ModuleResponse: Codable {
    let result_id: Int?
    let result_text: String?
    let timeout: Int
    let modules: [Module]?

    enum CodingKeys: String, CodingKey {
        case result_text = "result_text"
        case result_id = "result_id"
        case timeout = "timeout"
        case modules = "modules"
    }
}

struct Module: Codable {
    let id: Int
}

Only get timeout value, others No value associated with key CodingKeys.....

Thnks a lot!

EssoAwessoLNJ commented 4 years ago

Hello @alexllao . Have you please succeed ?