Search code examples
objective-cxmlxcodexpathgdataxml

GDataXML, namespaces, and xpath


I'm having trouble parsing XML using xpath and GDataXML -- using an xpath tester, my string seems that it should work, but I think adding in the namespace is interfering with it working.

XML:

<?xml version="1.0" encoding="utf-8"?>

<Autodiscover xmlns='http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006'>
          <Response xmlns='http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a'>
        <Account>
        <Protocol>
                <Type>EXPR</Type>
                <EwsUrl>https://server.my.dom/EWS/Exchange.asmx</EwsUrl>
        </Protocol>
        </Account>
      </Response>
</Autodiscover>

My attempt to parse it is as follows:

NSDictionary *namespaceMappings = [NSDictionary dictionaryWithObjectsAndKeys:@"http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a", @"response", nil];

    NSArray *idList = [doc nodesForXPath:@"//response:Protocol[Type='EXPR']/EwsUrl" namespaces:namespaceMappings error:nil];

I've also tried leaving out the namespace with the following:

NSArray *idList = [doc nodesForXPath:@"//Protocol[Type='EXPR']/EwsUrl" error:nil];

In both scenarios, idList has 0 members. I feel as if I'm just tossing things against the wall now to see if anything sticks. Can someone show me the way?

Thanks!


Solution

  • As for the XPath, you need //response:Protocol[response:Type='EXPR']/response:EwsUrl. I can't help with the objective-c stuff.