1

Am trying to convert the following xml tag:

<MTag media="wifi">122</MTag>

to an equivalent type, but am not able to find any way from the provided examples to do it.

Have tried,

struct Profile: XMLIndexerDeserializable {
// some other elements...
    let MTag: MTagElement

    static func deserialize(_ node: XMLIndexer) throws -> Profile{
         return try SMCPreferenceProfile(
            updateInterval: node["MTag"].value()
         )
    }
}

and correspondingly,

struct MTagElement: XMLIndexerDeserializable {
    let media: String
    let value: Int

    static func deserialize(_ node: XMLIndexer) throws -> MTagElement{
        return try MTagElement(
            media: node.value(ofAttribute: "media"),
            value: node["MTag"].value()
        )
    }
}

which is anyways wrong. What is the way to convert the following tag to its equivalent custom type?

Shane D
  • 834
  • 9
  • 23

1 Answers1

1

I am trying to put the attribute value in a separate property.

struct Profile: XMLIndexerDeserializable {
// some other elements...
    let mTag: Int
    let mTagMedia: String

    static func deserialize(_ node: XMLIndexer) throws -> Profile{
         return try SMCPreferenceProfile(
            mTag: node["MTag"].value(),
            mTagMedia: node["MTag"].value(ofAttribute: "media")
         )
    }
}

If is there any other way to properly solve this problem, then please advise.

Shane D
  • 834
  • 9
  • 23