Learn more with dummies

Enter your email to join our mailing list for FREE content right to your inbox. Easy!

Parsing an XML Response from the Cloud

By Neal Goldstein

Part of iOS Cloud Development For Dummies Cheat Sheet

When you use a web service that’s based in the cloud, your response might be in XML. If, when working with your cloud-based web service, you were to enter the following in your web browser

State Building&

you’d get back some XML — this, for example:


Since XML doesn’t exactly express itself in ways that are easy to understand, you would then have to parse whatever it is that XML gives you.

Remember XML is made up of elements that have start and end tags. To get at the information through iCloud, you use the NSXMLParser class that uses the delegation pattern. Here’s how that would work:

NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data];
[xmlParser setDelegate:self];
[xmlParser parse];

It turns out that there are four NSXMLParser delegate methods you will be implementing to parse an XML data structure:


parser:didStartElement:namespaceURI:qualifiedName:attributes: lets you know that the parser has found an element with a tag, <lat> for example, and it’s up to you to extract the data in the parser:foundCharacters: method.