Pugalmuni
Pugalmuni

Reputation: 9390

How to parse the xml data using NSXML Parser in iPhone?

I want to parse the XML data using NSXMLParser. In my root node is location and i want to extract the values for street, city, state and postal_code. I could take the name attribute values and how can i take the inner values of address node.

Here the xml node is,

<location id="10001">
<name>Pugal Devan</name>
    <address>
        <street>112, Jawahar Street </street>
        <city>Kolkata</city>
        <state>West Bengal</state>
        <postal_code>10002</postal_code>
</address>
</location>

Thanks!

Upvotes: 1

Views: 928

Answers (1)

FreeAsInBeer
FreeAsInBeer

Reputation: 12979

You could create a class that looks like:

@interface Location {

    NSString* name;
    NSString* street;
    NSString* city;
    NSString* state;
    NSString* postalCode;

}

Then just use the normal methods to parse the XML while creating Location objects to hold the parsed data. Here is a very thorough example on how to parse the data.

Upvotes: 1

Related Questions