使用更复杂的xml文档

时间:2013-10-30 11:02:03

标签: ios xml arrays

大家好我正在使用gdataxml库,正在使用示例文件:http://daniarnaout.com/School.xml

NSData *xmlData = [[NSMutableData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://daniarnaout.com/School.xml"]];
GDataXMLDocument *doc =[[GDataXMLDocument alloc] initWithData:xmlData options:0 error:nil];

NSArray *names =[doc nodesForXPath:@"//School/Student/Name" error:nil];
for(GDataXMLElement *name in names) { NSLog(@"name: %@ \n",name.stringValue); }

这很有效,但现在我想继续使用真实文档ftp://ftp2.bom.gov.au/anon/gen/fwo/IDV10753.xml

我可以使用NSLog(@"%@",doc.rootElement);

将xml打印到日志中

但如果我将xpath更改为//product/forecast/,我没有得到任何东西。

基本上我想获取<area aac="VIC_PT025"

的详细信息

我做错了什么?

1 个答案:

答案 0 :(得分:0)

为什么在这里使用nil(错误)?

NSArray *names =[doc nodesForXPath:@"//School/Student/Name" error:nil];

您没有发现错误。对于第二个XML,您可能已经知道xpath存在问题。而不是//product/forecast/,删除表达式末尾的额外/;你需要//product/forecast