C.Johns
C.Johns

Reputation: 10245

how to parse this xml data with NSXMLParser

I am trying to figure out how I can parse this xml :

<item>
    <title>
        <![CDATA[Preview: Courtney Crumrin and the Night Things Special Edition]]>
    </title>
    <description><![CDATA[]]></description>
    <pubDate>Tue, 20 Dec 2011 11:52:48 -0800</pubDate>
    <link>http://www.comicbookresources.com/?page=preview&amp;id=10864</link>
    <guid>http://www.comicbookresources.com/?page=preview&amp;id=10864</guid>
</item>

There are two issues, the structure.. there are many items, So I am thinking of creating a NSMutableArray with a NSDictionary that can hold these other values inside the item... would this be correct if so how to you pass those other values into the NSDictionary?

Also the other question is how do i deal with the CDATA? dose it just get ignored or do I have to do something special with it?

Upvotes: 0

Views: 632

Answers (1)

Caleb
Caleb

Reputation: 125037

Sure, it's fine to use an array of dictionaries. You'll generally want to use a mutable array of mutable dictionaries. Each time you start a new <item> element, create a new dictionary and start populating it as you receive subelements. When you get to the closing </item> tag, add the dictionary to the array.

As for the CDATA, your parser delegate should implement the -parser:foundCDATA: method. Then, your xml parser will simply report the data by calling that method, much as it calls -parser:foundCharacters: for regular character data.

Upvotes: 2

Related Questions