TouchXML 命名空间解析?
我试图通过 TouchXML 解析以下 XML:
<s:Envelope xmlns:s="namespace_1">
<s:Body>
<DefinedEntitiesResponse xmlns="namespace_2">
<DefinedEntitiesResult xmlns:a="namespace_3" xmlns:i="namespace_4">
<a:DefinedEntity>
<a:Description>Some Description</a:Description>
<a:Name>Some entity name</a:Name>
</a:DefinedEntity>
</DefinedEntitiesResult>
</DefinedEntitiesResponse>
</s:Body>
</s:Envelope>
我尝试像这样解析:
CXMLDocument *doc = [[[CXMLDocument alloc] initWithXMLString:[request responseString] options:0 error:nil] autorelease];
NSArray *resultNodes = [doc nodesForXPath:@"/s:Envelope" error:nil];
NSLog(@"Resultnodes: %@", resultNodes);
并收到错误:
XPath error : Undefined namespace prefix
XPath error : Invalid expression
问题 1:我做错了什么? 问题 2:我应该使用 TouchXML 作为库,还是有更简单、更好的东西?
I am trying to parse the following XML via TouchXML:
<s:Envelope xmlns:s="namespace_1">
<s:Body>
<DefinedEntitiesResponse xmlns="namespace_2">
<DefinedEntitiesResult xmlns:a="namespace_3" xmlns:i="namespace_4">
<a:DefinedEntity>
<a:Description>Some Description</a:Description>
<a:Name>Some entity name</a:Name>
</a:DefinedEntity>
</DefinedEntitiesResult>
</DefinedEntitiesResponse>
</s:Body>
</s:Envelope>
I try to parse this like so:
CXMLDocument *doc = [[[CXMLDocument alloc] initWithXMLString:[request responseString] options:0 error:nil] autorelease];
NSArray *resultNodes = [doc nodesForXPath:@"/s:Envelope" error:nil];
NSLog(@"Resultnodes: %@", resultNodes);
And getting the error:
XPath error : Undefined namespace prefix
XPath error : Invalid expression
Question 1: What am I doing wrong?
Question 2: Should I use TouchXML as a library, or is there something that works easier and better?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用以下 github 上的项目 将 XML 解析为 NSDictionary。然后,您可以使用 NSPredicate 来查找已解析字典中的值。
Use the following project on github to parse your XML into NSDictionary. You can then use
NSPredicate
to look up values in the parsed dictionary.