objective c - iPhone XML Parsing problem -
i trying extract title xml:
<entry> ... <title type="html">some title</title> <published>2011-02-07t00:04:16z</published> <updated>2011-02-07t00:04:16z</updated> ... </entry> in nsxmlparsing's didstartelement code:
if ([elementname isequaltostring:@"entry"]) { item = [[nsmutabledictionary alloc] init]; } if([elementname isequaltostring:@"title"]) { currentelement = [elementname copy]; currenttitle = [[nsmutablestring alloc] init]; } in foundcharacters:
if ([currentelement isequaltostring:@"title"]) { [currenttitle appendstring:string]; } in didendelement:
if ([elementname isequaltostring:@"entry"]) { [item setobject:currenttitle forkey:@"title"]; [currentelement release]; currentelement = nil; [item release]; item = nil; } the problem reason when gets didendelement currenttitle has got 3 node's content, its:
some title2011-02-07t00:04:16z2011-02-07t00:04:16z
i don't why picking published , updated node , appending them title string.
you set currentelement @"title" in didstartelement: never unset it. first element in particular xml file title, set currentelement , every foundcharacters: thereafter append them. change didstartelement: to:
currentelement = [elementname copy]; if ([elementname isequaltostring:@"entry"]) { item = [[nsmutabledictionary alloc] init]; } if([elementname isequaltostring:@"title"]) { currenttitle = [[nsmutablestring alloc] init]; }
Comments
Post a Comment