0

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

how would I set didStartElement? I would use if ([elementName isEqualToString:@"item"]) to set up the mutablearray but what would I do to set up the dictionary?
The mutable array should be an instance variable on the class implementing the NSXMLParserDelegate methods.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.