TBXML parsing issue while the value cannot get in UILabel

Posted by Dany on Programmers See other posts from Programmers or by Dany
Published on 2012-07-05T14:09:12Z Indexed on 2012/07/05 15:22 UTC
Read the original article Hit count: 275

Filed under:
|
|

In my app I'm using TBXML parser where I need to get a value from xml file and print it on the label.

This is my xml file in server

  <gold>
 <price>
 <title>22 K Gold</title>
  </price>
  <price>
  <title>24 K Gold</title>
  </price>
    </gold>

any my Viewcontroller.h looks like

 #import <UIKit/UIKit.h>
 #import "TBXML.h"

  @interface ViewController : UIViewController{

 IBOutlet UILabel *lab;
 IBOutlet UILabel *lab1;
 TBXML *tbxml;
 }



  @end

and my Viewcontrooler.m looks like

   - (void)viewDidLoad
    {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSData *xmlData = [[NSData alloc]initWithContentsOfURL:[NSURL  URLWithString:@"http://www.abcde.com/sample.xml"]];
   tbxml = [[TBXML alloc]initWithXMLData:xmlData];


   TBXMLElement * root = tbxml.rootXMLElement;

   if (root)
  {
   TBXMLElement * elem_PLANT = [TBXML childElementNamed:@"price" parentElement:root];
   while (elem_PLANT !=nil)
  {
    TBXMLElement * elem_BOTANICAL = [TBXML childElementNamed:@"title" parentElement:elem_PLANT];
NSString *botanicalName = [TBXML textForElement:elem_BOTANICAL];
    lab.text=[NSString stringWithFormat:@"re %@", botanicalName];

   elem_PLANT = [TBXML nextSiblingNamed:@"price" searchFromElement:elem_PLANT]; 

elem_BOTANICAL = [TBXML childElementNamed:@"title" parentElement:elem_PLANT]; 

botanicalName = [TBXML textForElement:elem_BOTANICAL];
lab1.text=[NSString stringWithFormat:@"re %@", botanicalName];
}
  }

}

I'm getting BAD_ACCESS thread. Am I missing anything?

© Programmers or respective owner

Related posts about iphone

Related posts about ios