1

I am trying to parse this xml to my application, but my NSDictionary is always nil when I debug

This xml

<DADOS_MESA>
    <MESA>
        <Id>1076</Id>
        <Date>2015-05-08T09:44:25.343</Date>
    </MESA>
<DADOS_MESA>

I am requesting this XML from my WS, with

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://myIP/Services.asmx/GetDetails?CId=02&SId=01"]];

Then I create an NSDictionary

NSDictionary *xml = [NSDictionary dictionaryWithContentsOfURL:url];

The NSDictionary always come nil(I don't know why), Thanks

ErasmoOliveira
  • 1,416
  • 2
  • 20
  • 40
  • 1
    I'd recommend this library, iOS doesn't support XML this way by default: https://github.com/nicklockwood/XMLDictionary – Logan Jun 08 '15 at 13:43

2 Answers2

4

Use: NSXMLParser & Darshan Answer

Community
  • 1
  • 1
Vicky
  • 602
  • 5
  • 16
2

You could use the NSXMLParser to do this. Here is a sample code.

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://myIP/Services.asmx/GetDetails?CId=02&SId=01"]];
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
parser.delegate = self;
[parser parse];

-(void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI
qualifiedName:(NSString*)qualifiedName attributes:(NSDictionary*)attributeDict
{
    //Use attributeDict to get parsed XML into NSDictionary
}
lead_the_zeppelin
  • 2,017
  • 13
  • 23