使用gdata xml命名空间parsingxml

我正在开发一个iOS应用程序,我用gdataxmlparsing我的XML,但我做错了,我的nslog是空

NSError *error = nil; GDataXMLDocument *xmlResult = [[GDataXMLDocument alloc] initWithData:data options:0 error:&error]; if (error) { NSLog(@"%@",error); } 

的NSLog(@ “%@”,xmlResult.rootElement); 我的根元素是完美的,错误是与tempArray

 NSArray *tempArray = [xmlResult nodesForXPath:@"//message/error/value" error:&error]; 

NSLog(@“mon array%@”,tempArray);

我的数组是null,

我的XML是这样的:

 <message xmlns="http://.....Api" xmlns:i="http://www.w3.org/...."> <error i:nil="true"/> <value> 

我是sur我的问题是与命名空间,但我不怎么做呢?

感谢您的回答

经过一些GDataXMLNodetesting后,我的答案是:

 NSArray *tempArray = [xmlResult nodesForXPath:@"//_def_ns:message/_def_ns:error/_def_ns:value" error:&error]; 

你可以在GDataXMLNode.h中看到这个注释:

 // This implementation of nodesForXPath registers namespaces only from the // document's root node. _def_ns may be used as a prefix for the default // namespace, though there's no guarantee that the default namespace will // be consistenly the same namespace in server responses. 

它声明,你实际上可以使用_def_ns作为你的命名空间。 但是,如果文档中有其他名称空间,也可以设置自己的名称空间。

 NSDictionary *myNS = [NSDictionary dictionaryWithObjectsAndKeys: @"http://.....Api", @"ns1", @"http://.....Other_Api", @"ns2", nil]; NSArray *tempArray = [xmlResult nodesForXPath:@"//ns1:message/ns1:error/ns1:value" namespaces:myNS error:&error];