evermeer / alamofirexmltoobjects Goto Github PK
View Code? Open in Web Editor NEWFetch a XML feed and parse it into objects
License: Other
Fetch a XML feed and parse it into objects
License: Other
Hey,
I would really like to use your CocoaPod but I can't get it to work. Even the sample code won't work.
Any suggestions why this error is popping up ?
Error in line:
api.responseObject { (response: Result< WeatherResponse, NSError>) in
I have hit this problem with a new API XML feed.
2016-04-12 13:35:29.178 Vault[55707:19474924]
WARNING: The class 'XXX' is not key value coding-compliant for the key '__name'
There is no support for optional type, array of optionals or enum properties.
As a workaround you can implement the function 'setValue forUndefinedKey' for this. See the unit tests for more information
previously, working with a different API (Json) and your AlamofireJsonToObjects library I solved the same problem by defining all the Json keys and also following your advice to add
override internal func propertyMapping() -> [(String?, String?)] {
return [("ignoredProperty",nil), ("propertyInObject","keyInJson")]
}
I am now stuck on this XML feed API and using AlamofireXmlToObjects, since it seems to generate some internal values I don't recognise from the API docs (_name, _version, _copyright) and there are also quite a few keys I would prefer to ignore
Adding the propertyMapping() override as above doesn't help -- I noticed the final parameter is "keyInJson".
Would appreciate any advice you might have with this
Hi,
I'm trying to parse the following XML document:
<channel name="HMIP-SWDO 0000D3C98C9E08:0" ise_id="1281" visible="true" operate="true">
<datapoint name="HmIP-RF.0000D3C98C9E08:0.CONFIG_PENDING" type="CONFIG_PENDING" ise_id="1282" value="" valuetype="2" valueunit="" timestamp="0" operations="0"/>
<datapoint name="HmIP-RF.0000D3C98C9E08:0.DUTY_CYCLE" type="DUTY_CYCLE" ise_id="1286" value="false" valuetype="2" valueunit="" timestamp="1472726147" operations="5"/>
<datapoint name="HmIP-RF.0000D3C98C9E08:0.ERROR_CODE" type="ERROR_CODE" ise_id="1287" value="0" valuetype="8" valueunit="" timestamp="1472726147" operations="5"/>
<datapoint name="HmIP-RF.0000D3C98C9E08:0.LOW_BAT" type="LOW_BAT" ise_id="1288" value="false" valuetype="2" valueunit="" timestamp="1472726147" operations="5"/>
<datapoint name="HmIP-RF.0000D3C98C9E08:0.OPERATING_VOLTAGE" type="OPERATING_VOLTAGE" ise_id="1292" value="1.300000" valuetype="4" valueunit="" timestamp="1472726147" operations="5"/>
<datapoint name="HmIP-RF.0000D3C98C9E08:0.SABOTAGE" type="SABOTAGE" ise_id="1293" value="false" valuetype="2" valueunit="" timestamp="1472726147" operations="5"/>
<datapoint name="HmIP-RF.0000D3C98C9E08:0.UNREACH" type="UNREACH" ise_id="1297" value="false" valuetype="2" valueunit="" timestamp="1472726147" operations="5"/>
</channel>
<channel name="HMIP-SWDO 0000D3C98C9E08:1" ise_id="1301" visible="true" operate="true">
<datapoint name="HmIP-RF.0000D3C98C9E08:1.STATE" type="STATE" ise_id="1302" value="0" valuetype="16" valueunit="""" timestamp="1472726147" operations="5"/>
</channel>
When I parse it with AlamofireXMLToObjects it throws fatal error: NSArray element failed to match the Swift Array Element type when there only is one child for the channel like here:
<channel name="HMIP-SWDO 0000D3C98C9E08:1" ise_id="1301" visible="true" operate="true">
<datapoint name="HmIP-RF.0000D3C98C9E08:1.STATE" type="STATE" ise_id="1302" value="0" valuetype="16" valueunit="""" timestamp="1472726147" operations="5"/>
</channel>
datapoint [annHomeAutomation.HMDatapoint] 1 value
[0] __NSDictionaryM * 7 key/value pairs 0x00007f8f59f717e0
[0] (null) @"_value" : (no summary)
[1] (null) @"_name" : @"HmIP-RF.0000D3C98C9E08:1.STATE"
[2] (null) @"_ise_id" : (no summary)
[3] (null) @"_type" : (no summary)
[4] (null) @"_valueunit" : (no summary)
[5] (null) @"_valuetype" : (no summary)
[6] (null) @"_timestamp" : @"1472726457"
for some reason it reads out the data but won't create the desired HMDatapoint object.
Hi Edwin,
Here's a section of the file I'm trying to parse:
<allgames>
<StateProv stateprov_name="Arkansas" stateprov_id="AR">
<game game_id="101" game_name="Powerball" update_time="WED 2016-06-01 23:00:34 EST">
<lastdraw_date>06/01/2016</lastdraw_date>
<lastdraw_numbers>23-30-33-40-69, Powerball: 12, Power Play: 5</lastdraw_numbers>
<nextdraw_date>06/04/2016</nextdraw_date>
<jackpot date="06/04/2016">110000000</jackpot>
</game>
<game game_id="113" game_name="MEGA Millions" update_time="FRI 2016-06-03 23:01:31 EST">
<lastdraw_date>06/03/2016</lastdraw_date>
<lastdraw_numbers>32-54-65-66-71, Mega Ball: 10, Megaplier: 3</lastdraw_numbers>
<nextdraw_date>06/07/2016</nextdraw_date>
<jackpot date="06/03/2016">251000000</jackpot>
</game>
<game game_id="132" game_name="Lucky For Life" update_time="THU 2016-06-02 22:54:02 EST">
<lastdraw_date>06/02/2016</lastdraw_date>
<lastdraw_numbers>11-19-36-37-42, Lucky Ball: 10</lastdraw_numbers>
<nextdraw_date>06/06/2016</nextdraw_date>
</game>
<game game_id="AR1" game_name="Natural State Jackpot" update_time="FRI 2016-06-03 21:19:03 EST">
<lastdraw_date>06/03/2016</lastdraw_date>
<lastdraw_numbers>04-18-19-21-33</lastdraw_numbers>
<nextdraw_date>06/04/2016</nextdraw_date>
<jackpot date="06/04/2016">105000</jackpot>
</game>
<game game_id="ARD" game_name="Cash 4 Midday" update_time="FRI 2016-06-03 14:10:03 EST">
<lastdraw_date>06/03/2016</lastdraw_date>
<lastdraw_numbers>6-0-8-3</lastdraw_numbers>
<nextdraw_date>06/04/2016</nextdraw_date>
</game>
<game game_id="ARB" game_name="Cash 3 Midday" update_time="FRI 2016-06-03 14:09:03 EST">
<lastdraw_date>06/03/2016</lastdraw_date>
<lastdraw_numbers>4-7-4</lastdraw_numbers>
<nextdraw_date>06/04/2016</nextdraw_date>
</game>
<game game_id="ARC" game_name="Cash 4 Evening" update_time="FRI 2016-06-03 20:10:02 EST">
<lastdraw_date>06/03/2016</lastdraw_date>
<lastdraw_numbers>2-6-4-1</lastdraw_numbers>
<nextdraw_date>06/04/2016</nextdraw_date>
</game>
<game game_id="ARA" game_name="Cash 3 Evening" update_time="FRI 2016-06-03 20:12:12 EST">
<lastdraw_date>06/03/2016</lastdraw_date>
<lastdraw_numbers>5-2-0</lastdraw_numbers>
<nextdraw_date>06/04/2016</nextdraw_date>
</game>
</StateProv>
Some sections of my code:
import UIKit
import Alamofire
import AlamofireXmlToObjects
import ObjectMapper
import AlamofireObjectMapper
import EVReflection
class LotteryResponse: EVObject {
var stateprov_name: String?
var gameData: [game] = [game]()
}
class game: EVObject {
var game_name: String?
var lastdraw_date: String?
var lastdraw_numbers: String?
var nextdraw_date: String?
var jackpot: String?
}
class AlamofireXmlToObjects {
func responseObject() {
let urlString = "http://www.lotterynumbersxml.com/lotterydata/[email protected]/kjw8uwe/lottery_us.xml"
Alamofire.request(.GET, urlString, parameters: nil)
.responseObject { (response: Result< LotteryResponse, NSError>) in
if let LotteryResponse = response.value {
}
}
}
}
It does not look like this project has been converted to Swift 3. I tried letting Xcode 8 do the conversion but resulted in about 30 compiler errors.
Hi Evermeer,
The XML Response that I sent you wrong, there was a mistake while copy paste. Sorry for wasting your time and energy. Here is the correct XML.
<requestl> <qlist> <piname>MONTY CHICOLA</piname> <picell>318-730-5705</picell> <pihome>318-442-3893</pihome> <rinum>FAAAAANI</rinum> <dev>$00046728</dev> <riapt>KFOE</riapt> <rifbo>00001</rifbo> <ridatr>08/04/2016 07:06</ridatr> <ridats/> <riacft>N2244</riacft> <riftyp>AVGAS</riftyp> <rifunt>GAL</rifunt> <rifuel>0</rifuel> </qlist> <qlist> <piname>MONTY CHICOLA</piname> <picell>318-730-5705</picell> <pihome>318-442-3893</pihome> <rinum>FAAAAANL</rinum> <dev>$00046728</dev> <riapt>KFOE</riapt> <rifbo>00001</rifbo> <ridatr>08/04/2016-18:58</ridatr> <ridats/> <riacft>N55MC</riacft> <riftyp>AVGAS</riftyp> <rifunt>GAL</rifunt> <rifuel>00100</rifuel> </qlist> <qlist> <piname>MONTY CHICOLA</piname> <picell>318-730-5705</picell> <pihome>318-442-3893</pihome> <rinum>FAAAAANM</rinum> <dev>$00046728</dev> <riapt>KAEX</riapt> <rifbo>00001</rifbo> <ridatr>08/04/2016-19:01</ridatr> <ridats/> <riacft>N5JT</riacft> <riftyp>JET/A</riftyp> <rifunt>GAL</rifunt> <rifuel>100</rifuel> </qlist> <qlist> <piname>MONTY CHICOLA</piname> <picell>318-730-5705</picell> <pihome>318-442-3893</pihome> <rinum>FAAAAANN</rinum> <dev>$00046728</dev> <riapt>KAEX</riapt> <rifbo>00001</rifbo> <ridatr>08/04/2016-19:06</ridatr> <ridats/> <riacft>N2244</riacft> <riftyp>AVGAS</riftyp> <rifunt>GAL</rifunt> <rifuel>0</rifuel> </qlist> </requestl>
Also I have a class containing all the properties under qlist. What I want is that the properties under qlist to be parsed as an object of the class.
Please help me out with this.
Thanks in advance.
I am trying to parse a XML which looks like this :
<requestl> <qlist> <piname>MONTY CHICOLA</piname> <picell>318-730-5705</picell> <pihome>318-442-3893</pihome> <rinum>FAAAAAM7</rinum> <dev>$00046728</dev> <riapt>KFOE</riapt> <rifbo>00001</rifbo> <ridatr>08/02/2016-03:05</ridatr> <ridats/> <riacft>N5WF</riacft> <riftyp>JET/A</riftyp> <rifunt>GAL</rifunt> <rifuel>46549</rifuel> <xifptx/> <rifpt>05990</rifpt> <xifpsx/> <rifps>09990</rifps> <riinf1>SHELL 15 W 50</riinf1> <riinf2/> <ritarr>03:03</ritarr> <ridata>08/02/2016</ridata> <ridumd>08/02/2016 03:03</ridumd> <risort>20160802 20160802</risort> <ridumy>08/02/2016 03:03</ridumy> <ritdep>03:03</ritdep> <riddat>08/02/2016</riddat> <rinotr>N</rinotr> <rinotc>N</rinotc> <rinots>*</rinots> <ripdrp>0</ripdrp> <rippck>0</rippck> <riex2/> <xifpmx/> <rifpm>09960</rifpm> <xifpax/> <rifpa>90999</rifpa> <xifpix/> <rifpi>99990</rifpi> <xifpox/> <rifpo>00999</rifpo> <rihang/> <ristat>New Request</ristat> <rirepy/> <riext1>Crew Car</riext1> <riex1>N</riex1> <paname>CESSNA</paname> <pamodl>550</pamodl> <pafuel>AVGAS</pafuel> <riinst/> <riloc>H-1</riloc> <rifpum>00000</rifpum> <ritpum/> <riqoil>940</riqoil> <ritoil>SHELL 15 W 50</ritoil> <riusro/> <riapu/> <fbnam>Forbes Million Air</fbnam> <fbadd1>Forbes Field Bldg 610</fbadd1> <fbphon>877-862-0950</fbphon> <fbnam>Forbes Million Air</fbnam> </qlist> </requestl>
I am not able to parse and extract data.
Can you please help me out.
Thank You
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.