Search code examples
objective-cxmlxcodeparsingxcode4

Handling complex xml with multiple delegates


I'm currently trying to create a parser to populate my core data database. I have tried using NSXMLParser, where I realized that would be kinda difficult. Because I cant handle the xml document well enough.

Then I searched and found that I could use multiple delegates for handling complex documents.

I tried to find some tutorials/guides/examples for this. But I only examples with simple XML files.

I found this similar to mine. NSXMLParser with multiple delegates But the guy doesn't get any answers.

Maybe some people here have some examples?

Thanks in advance.


Solution

  • The XML structure of the guy you mentioned is quite easy to parse, he most probably is doing it wrong in the code he didn't show. You do not need to use multiple delegates to parse an XML file. You've already said you've got some sort of data model in your app. You need to create an NSXMLParser subclass and temporary data model objects. Then listen which tag is currently being parsed and store the data in your temporary objects, saving them into the NSManagedObjectContext. Really its that simple. If that doesn't makes it clear, put your xml document in the question and I'll try to explain this with as much code as possible.