开发者

TouchXML namespace resolving?

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>
         </D开发者_如何学编程efinedEntitiesResult>
      </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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜