iphone - XML attribute pasrsing problem -
i have parse xml , link of xml is
http://qasimshah.sitesled.com/schedule.xml
and may parse is:
-(ibaction)autologinbtn{ nsstring *url=[nsstring stringwithformat: @"http://qasimshah.sitesled.com/schedule.xml"]; [self parsexmlfileaturl:url]; } - (void)parsexmlfileaturl:(nsstring *)url { xmldataarray1 = [[nsmutablearray alloc] init]; //you must convert path proper nsurl or won't work nsurl *xmlurl = [nsurl urlwithstring:url]; // here, reason have use nsclassfromstring when trying alloc nsxmlparser, otherwise object not found error // may necessary toolchain nsxmlparser *rssparser = [[nsxmlparser alloc] initwithcontentsofurl:xmlurl]; // set self delegate of parser receive parser delegate methods callbacks. [rssparser setdelegate:self]; // depending on xml document you're parsing, may want enable these features of nsxmlparser. [rssparser setshouldprocessnamespaces:no]; [rssparser setshouldreportnamespaceprefixes:no]; [rssparser setshouldresolveexternalentities:no]; [rssparser parse]; } -(void)parser:(nsxmlparser *)parser parseerroroccurred:(nserror *)parseerror{ nslog(@"error on xml parse: %@", [parseerror localizeddescription] ); } - (void)parser:(nsxmlparser *)parser didstartelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname attributes:(nsdictionary *)attributedict{ //nslog(@"found element: %@", elementname); currentelement = [elementname copy]; if ([elementname isequaltostring:@"sports"]) { // clear out our story item caches... item = [[nsmutabledictionary alloc] init]; currenttitle = [[nsmutablestring alloc] init]; } } - (void)parser:(nsxmlparser *)parser didendelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname{ if ([elementname isequaltostring:@"sport"]) { [item setobject:currenttitle forkey:@"id"]; [xmldataarray1 addobject:[item copy]]; nslog(@"id: %@", currenttitle); } }
but when try 'id' or name
parser detect not return me value. how can value?
try this. can values this.
- (void)parser:(nsxmlparser *)parser didstartelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname attributes:(nsdictionary *)attributedict { if([elementname isequaltostring:@"sport"]) { nsstring *s = [nsstring stringwithformat:@"%@",elementname]; nslog(@"%@",s); nsstring *s1 =[nsstring stringwithformat:@"%@",[attributedict valueforkey:@"id"]]; nslog(@"%@",s1); nsstring *s2 =[nsstring stringwithformat:@"%@",[attributedict valueforkey:@"name"]]; nslog(@"%@",s2); nsstring *s3 =[nsstring stringwithformat:@"%@",[attributedict valueforkey:@"abbr"]]; nslog(@"%@",s3); } }
Comments
Post a Comment