@robertomachorro thank you very much for your answer but I’ve still problem.
thank you very much for the answer but I’ve still problems
first I’m using this. it’s the same of yours.
this is a piece oaf my xml
<?xml version="1.0" encoding="utf-8" ?> <ns2:body xmlns:ns2="http://www.jaapp.it"> <airportlist> <hash>F16443A97073B98718174A8AFCDE5F65</hash> <changed>true</changed> <airports> <airport> <id>AAL_APT_0001</id><code>AAL</code> <name>Int</name> <citycode>AAL</citycode> <city>Aalborg</city> <countrycode>DK</countrycode> <country>Danimarca</country> <continent>Europa</continent> <latitude>57,09275891</latitude> <longitude>9,849243164</longitude> </airport> <airport> <id>AES_APT_0019</id><code>AES</code> <name>Aalesund Vigra</name> <citycode>AES</citycode> <city>Aalesund</city> <countrycode>NO</countrycode> <country>Norvegia</country> <continent>Europa</continent> <latitude>62,5625</latitude> <longitude>6,119699955</longitude> </airport> <airport> <id>AAR_APT_0001</id><code>AAR</code> <name>Aarhus Airport</name> <citycode>AAR</citycode> <city>Aarhus</city> <countrycode>DK</countrycode> <country>Danimarca</country> <continent>Europa</continent> <latitude>56,2999992</latitude> <longitude>10,6190004</longitude> </airport> </airports> </airportlist> </ns2:body>
Now I’ve no error from decoder but the objects are empty
this is my code:
AF.request("url_to_my_api").responseData {
response in guard let airportList = response.data else { return }
let decoder = XMLDecoder()
decoder.shouldProcessNamespaces = true
let note = try! decoder.decode(AirportList.self, from: airportList)
print(note)
}
these are my model class
import Foundation
import XMLCoder
struct Airport:Codable, DynamicNodeDecoding {
let id:String
let code:String
let name:String
let cityCode:String
let city:String
let countryCode:String
let country:String
let continent:String
let latitude:String
let longitude:String
enum CodingKeys: String, CodingKey {
case id = "id"
case code = "code"
case name = "name"
case cityCode = "cityCode"
case city = "city"
case countryCode = "countryCode"
case country = "country"
case continent = "continent"
case latitude = "latitude"
case longitude = "longitude"
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decode(String.self, forKey: .id)
code = try container.decode(String.self, forKey: .code)
name = try container.decode(String.self, forKey: .name)
cityCode = try container.decode(String.self, forKey: .cityCode)
city = try container.decode(String.self, forKey: .city)
countryCode = try container.decode(String.self, forKey: .countryCode)
country = try container.decode(String.self, forKey: .country)
continent = try container.decode(String.self, forKey: .continent)
latitude = try container.decode(String.self, forKey: .latitude)
longitude = try container.decode(String.self, forKey: .longitude)
}
static func nodeDecoding(for key: CodingKey) -> XMLDecoder.NodeDecoding {
switch key {
case Airport.CodingKeys.id:
return .element
default:
return .element
}
}
}
import Foundation
import XMLCoder
struct AirportList: Codable {
var airportList:[Airport]
enum CodingKeys: String, CodingKey {
case airportList = "airport"
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
airportList = try container.decode([Airport].self, forKey: .airportList)
}
}
can you help me?