使用 gdata xml 解析带有名称空间的 xml
我正在开发一个ios应用程序,我正在用gdataxml解析我的xml,但我做错了,我的nslog是null
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>
我确信我的问题与命名空间有关,但我不知道该怎么做?
谢谢你的回答
i am developping an ios application and i am parsing my xml with gdataxml, but i am doing it wrong, my nslog is null
NSError *error = nil;
GDataXMLDocument *xmlResult = [[GDataXMLDocument alloc] initWithData:data options:0 error:&error];
if (error) {
NSLog(@"%@",error);
}
NSLog(@"%@",xmlResult.rootElement);
my root element is perfect, the error is with tempArray
NSArray *tempArray = [xmlResult nodesForXPath:@"//message/error/value" error:&error];
NSLog(@"mon array %@",tempArray);
my array is null,
my xml is like this :
<message xmlns="http://.....Api" xmlns:i="http://www.w3.org/....">
<error i:nil="true"/>
<value>
i am sur that my problème is with the namespace, but i don't how to do it ?
thanks for your answer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 GDataXMLNode 进行一些测试后,这是我的答案:
您可以在 GDataXMLNode.h 中看到此注释:
它指出您实际上可以使用 _def_ns 作为命名空间。但是,您也可以设置自己的命名空间,以防文档中存在其他命名空间。
After some testing with GDataXMLNode, here is my answer:
You can see this comment in GDataXMLNode.h:
It states that you can actually use _def_ns as your namespace. However, you can also set your own namespace in case there are other namespaces in your document.