IOS: How to read specific data in one list of XML -
when use nsxmlparser parse xml in iphone app, know how in scenario this:
> <title>l3178 : freiensteinau richtung grebenhain</title> // xml
but, if want extract data list, e.x. want lat , lon <>id>, how should deal that?
<>id> http://www.freiefahrt.info/?id=468b0243-e15c-4580-9ad2 14d8cf692999&lon=9.3495&lat=50.49465&country=de&filter=0&expires=2013-12-20t03:13:00 <>/id>
it strange if use instead of <>id>, disappear. so, have use ugly notation.
thank in advance!
create method extracts parameters urlstring
- (nsdictionary *)paramsfromurlstring:(nsstring *)urlstring { nsrange range = [urlstring rangeofstring:@"?"]; nsstring *substring = [urlstring substringfromindex:range.location+range.length]; nsarray *components = [substring componentsseparatedbystring:@"&"]; nsmutabledictionary *params = [nsmutabledictionary dictionary]; (nsstring *string in components) { nsrange subrange = [string rangeofstring:@"="]; nsstring *key = [string substringtoindex:subrange.location]; nsstring *value = [string substringfromindex:subrange.location+subrange.length]; [params setobject:value forkey:key]; } return params; }
from params find lat , lon
nsstring *urlstring = @"http://www.freiefahrt.info/?id=468b0243-e15c-4580-9ad2 14d8cf692999&lon=9.3495&lat=50.49465&country=de&filter=0&expires=2013-12-20t03:13:00"; nsdictionary *params = [self paramsfromurlstring:urlstring]; nsstring *latitude = params[@"lat"]; nsstring *longitude = params[@"lon"];
Comments
Post a Comment