I want to parse following XML, but i'm confused how to parse it because I have multiple nesting in a single record. Can any one give me a suggestion for this?
<daily_record>
<date>2011-04-17</date>
<gold>
<team_image>http://hockeypicks.com/ConfiMeter/nhl_images/vancouver.bmp</team_image>
<percentage>56%</percentage>
<status>WIN</status>
</gold>
<silver>
<team_image>http://hockeypicks.com/ConfiMeter/nhl_images/detroit.bmp</team_image>
<percentage>66%</percentage>
<status>LOST</status>
</silver>
<bronze>
<team_image>http://hockeypicks.com/ConfiMeter/nhl_images/nashville.bmp</team_image>
<percentage>66%</percentage>
<status>LOST</status>
</bronze>
<avg_conf>56.22%</avg_conf>
</daily_record>
NSData *data=[NSData dataWithContentsOfURL:myUrl.mURL];
NSString *string=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
DDXMLDocument *doc=[[[DDXMLDocument alloc] initWithXMLString:string options:0 error:nil] autorelease];
NSArray *docs=[doc nodesForXPath:@"//item" error:nil];
NSLog(@"Doc Count%i",[docs count]);
for (DDXMLElement *documents in docs)
{}
then in this for loop u can do something like this:
DDXMLNode *childNode=[documents childAtIndex:k];
DDXMLElement *childElement=(DDXMLElement *)childNode;
book.title=[childElement stringValue] ;
book.podLink=[[childElement attributeForName:@"url"] stringValue];//For Attributes
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.