Domanda

I tried to parse following String using TBXML.

<panel><start><post_id>4</post_id><user_id>2</user_id><post>Hyder here</post><created_on>2012-01-09 06:36:59</created_on><likes>0</likes><noc>0</noc><status>A</status></start><start><post_id>3</post_id><user_id>2</user_id><post>Hello hyder here</post><created_on>2012-01-09 06:34:09</created_on><likes>0</likes><noc>0</noc><status>A</status></start><start><post_id>2</post_id><user_id>0</user_id><post>Hi, This is Syed Hyder....</post><created_on>2012-01-09 01:07:36</created_on><likes>0</likes><noc>0</noc><status>A</status></start><start><post_id>1</post_id><user_id>0</user_id><post>Hello, gaurav....How are you.</post><created_on>2012-01-09 01:05:11</created_on><likes>0</likes><noc>0</noc><status>A</status></start></panel>

My code: -

NSMutableArray *newArr = [[NSMutableArray alloc] init];//21
    RXMLElement *rxml = [[RXMLElement alloc] initFromXMLString:response];
    [rxml iterate:@"panel.start" with:^(RXMLElement *start) {
        ModelPost *newPost = [[ModelPost alloc] init];
        newPost.message = [NSString stringWithFormat:@"%@", [start child:@"post"]];
        NSLog(@"Post = %@", [start child:@"post"]);
        [newArr addObject:newPost];
    }];

but I am unable to do it or enter in the iterate loop. Please help me to over come this by sample code, suggestions and tutorials. Thanks in Advance....

È stato utile?

Soluzione

 - (void)xmlparserurl{

//xml data url calling....

    tbxml = [[TBXML tbxmlWithURL:[NSURL URLWithString:@"http://karen.webmascot.com/iapi/orders.php?max_count=10"]] retain];


records = [NSMutableArray array];
[records retain];




//retrieving all data from the xml
if (tbxml.rootXMLElement){
    NSLog(@"inserting");
    [self traverseElement:tbxml.rootXMLElement];
}
[tbxml release];
}

- (void)traverseElement:(TBXMLElement *)element {
do {
    //NSLog(@"%@",[TBXML elementName:element]);
    if (element->firstChild) 
        [self traverseElement:element->firstChild];
    if ([[TBXML elementName:element] isEqualToString:@"start"]) {
        //NSLog(@"xml element checking");
        TBXMLElement *id = [TBXML childElementNamed:@"attribute name" parentElement:element];

//inserting into the mutable array      
[records addObject:[NSArray arrayWithObjects:
[TBXML textForElement:elementname],
[TBXML textForElement:elementname],
[TBXML textForElement:elementname],nil]];

    }

} while ((element = element->nextSibling)); 


[self.tableview reloadData];
}

i am only sending the code of retrieving the xml data. i am also sending the tutorial where you will get the answer of your further question.

http://www.tbxml.co.uk/TBXML/API.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top