我正在开发一个ios应用程序,我正在用gdataxml解析我的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);
我的数组为空,
我的xml是这样的:
<message xmlns="http://.....Api" xmlns:i="http://www.w3.org/....">
<error i:nil="true"/>
<value>
我确信我的问题与名称空间有关,但我不知道该怎么做?
感谢您的回答
使用 GDataXMLNode 进行一些测试后,这是我的答案:
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];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)