how to parse a huge xml file
I need to parse a xml file which is hu开发者_开发技巧ge in size. Its size will be little above 400-500 MB. My application is completely based upon this data. But parsing takes huge time. On iPhone it takes more then 10 minutes for every request that I make. I am using built in NSXMLParsers of iphone sdk to parse the data. What should i do now?
Thanks Pankaj
400-500 MB of XML is crazy on the iPhone. Look for alternatives.
For example, if you are including this file in your application, consider converting it to a sqlite or Core Data database and include that database in your app instead.
If you are downloading this data from the network, consider doing the same translation in-app and then throwing away the downloaded XML file.
As previously mentioned, XML is quite likely not the right format for that amount of data. If your XML has embedded image data, or something of that nature, you could possibly put that into the app's resource fork and simply have the XML reference files at the appropriate paths.
However, if you simply don't have any choice in the matter and must use XML, you might consider using the libxml library rather than NSXMLParser. The libxml parser is written in C, so using it is a little bit more work than NSXMLParser, but it's available on the device and depending on the structure of your XML it may provide significantly better performance than its Objective-C counterpart. You'll have to use SAX parsing in either case, of course.
Regardless of how you parse the XML I would echo the suggestion that you not keep your data in that format. Once you extract the information once try to convert it into something easier to work with. That way you at least limit the high performance cost to the initial use of the app.
精彩评论