在我的应用程序中,我正在使用 TBXML 解析器,我需要从 xml 文件中获取一个值并将其打印在标签上......这是我在服务器中的 xml 文件
<gold>
<price>
<title>22 K Gold</title>
</price>
<price>
<title>24 K Gold</title>
</price>
</gold>
任何我的 Viewcontroller.h 看起来像
#import <UIKit/UIKit.h>
#import "TBXML.h"
@interface ViewController : UIViewController{
IBOutlet UILabel *lab;
TBXML *tbxml;
}
@end
我的 Viewcontroller.m 看起来像
- (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];
}
}
}
我收到了 BAD_ACCESS 线程。我错过了什么吗...请帮助...