我试图通过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作为库,还是有更容易和更好的东西?