ios - Parse the Anchor tags and the content using NSXMLParse -


i want parse html tags inside "comparison" node

<comparison>     <a href="/cgi-bin/amazon.cgi?b0050amjyu">amazon.com</a>     ($34.36) |     <a href="/cgi-bin/walmart.cgi?16904483">walmart.com</a>     ($34.36) |     <a href="/cgi-bin/rakuten.cgi?219782579">rakuten.com</a>     ($34.36) |     <a href="/cgi-bin/bestbuy1.cgi?mp1307815397">bestbuy.com</a>     ($34.36) </comparison> 

the o\p getting is

 bestbuy.com ($34.36) 

the expected o\p

amazon.com ($34.36)   walmart.com ($34.36)  rakuten.com ($34.36)   bestbuy.com ($34.36) 

but want display 4 items. please help.

code

- (void)parser:(nsxmlparser *)parser didstartelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qualifiedname attributes:(nsdictionary *)attributedict {     currentelementvalue = [nsmutablestring string];     [uiapplication sharedapplication].networkactivityindicatorvisible = yes;     if ([elementname isequaltostring:@"item"]) {         dealslistobj = [[dealsparsingobjects alloc] init];     }  }  - (void)parser:(nsxmlparser *)parser foundcharacters:(nsstring *)string {     [currentelementvalue appendstring:string]; }  - (void)parser:(nsxmlparser *)parser didendelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname {     if ([elementname isequaltostring:@"short_title"]) {         dealslistobj.itemtitle = currentelementvalue;         currentelementvalue = nil;     }     else if ([elementname isequaltostring:@"final_price"]) {         dealslistobj.price = currentelementvalue;         currentelementvalue = nil;     }     //detail view     else if ([elementname isequaltostring:@"merchant"]) {         dealslistobj.itemmerchant = currentelementvalue;         currentelementvalue = nil;     }     else if ([elementname isequaltostring:@"getdeal"]) {         dealslistobj.itemgetdeal = currentelementvalue;         currentelementvalue = nil;     }     //comparison     else if ([elementname isequaltostring:@"comparison"]) {         dealslistobj.comparison = currentelementvalue;         currentelementvalue = nil;      }     else if ([elementname isequaltostring:@"item"]) {         [resultarray addobject:dealslistobj];         [dealslistobj release];         dealslistobj = nil;         currentelementvalue = nil;     } } 

it appears have dealsparsingobjects class nsmutablearray called commentsarray. instantiate array, when parsing begins reading <comparison> element.

but when parser has read <comparison> element, assign value property called comparison; doesn't added array. being default nsstring property (assumption on part), gets reassigned each time parser done reading <comparison> element.

edit:

parser:didstartelement:... called every time new element read. holds <a> tags. in method reset currentelementvalue. each <a> value reset empty string. last read value remains, value of last <a> tag plus trailing text.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -