[英]Issue in converting xml to custom type using swxmlhash
Am trying to convert the following xml tag: 我正在尝试转换以下xml标签:
<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?
如何将以下标记转换为其等效的自定义类型?
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. 如果还有其他方法可以正确解决此问题,请提出建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.