parse xml with namespaces with gdata xml

前端 未结 1 1102
夕颜
夕颜 2021-01-14 03:39

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          


        
相关标签:
1条回答
  • 2021-01-14 04:35

    After some testing with GDataXMLNode, here is my answer:

    NSArray *tempArray = [xmlResult nodesForXPath:@"//_def_ns:message/_def_ns:error/_def_ns:value" error:&error];
    

    You can see this comment in 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.
    

    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.

    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];
    
    0 讨论(0)
提交回复
热议问题