0

I'd like to use NSXMLParser to parse a large xml file. There are a few thousand elements on the root level, so it's too large for a tree based approach. Ideally, I would like to parse each of those one thousand elements individually into a tree and then do some (more complicated) parsing on them. I only need the string values (including the xml markup) of these root level elements which I can then hand off to my already existing tree based parser. I wasn't able to find out how to do that with NSXMLParser, if possible at all.

Imagine an xml file like this

<start>
 <record>
  <title>The Title</title>
  <content>Some content</content>
 </record>
 <record>
  <title>The Title</title>
  <content>Some content</content>
 </record>
</start>

For each record, I'd like to get a string containing <title>The Title</title> <content>Some content</content>.

hanno
  • 6,401
  • 8
  • 48
  • 80
  • I found a possible answer here: http://stackoverflow.com/questions/11735590/ios-combining-sax-and-dom-parsing – hanno Sep 09 '12 at 13:45
  • NSXMLParser does exactly what you want, so I don't know what the problem is. It will spit out the info as it goes along, and it is up to you to do something with it. It returns info via delegate methods. – borrrden Sep 09 '12 at 13:56
  • No it does not. In the above example it parses the and <content> elements. I just want the string `<title>The Title Some content`. – hanno Sep 09 '12 at 14:06
  • You mean you want one string containing both? – borrrden Sep 09 '12 at 23:40

1 Answers1

0

I ended up rewriting everything as a SAX parser. It is slightly more complicated to implement and fairly restrictive, but the speed up and memory usage is really worth it in my case.

hanno
  • 6,401
  • 8
  • 48
  • 80