开发者

How to efficiently parsing large xml files on iOS in order to store the content in SQLite ?

I'm using libxml2′s DOM parser in my iPhone app to parse a XML file with a hundred thousand lines.

I store the content retrieved into a SQLite database. However, this process takes several minutes to complete, too much to be user friendly. My feeling is the biggest part of the time gets lost writing the data into the database.

I'm looking now for any hints on how to make th开发者_开发技巧is process more efficient.


Try profiling your code with Instruments! Check for the parts of your own code that are taking the most time! See if you can take a different approach (or post the slow code for suggestions)! If possible, use NSOperation / NSOperationQueue to provide progress feedback to the user!

!


Definitely agree with JNozzi. Profile your code first to see where the largest performance bottlenecks are. It's not clear whether it's the XML DOM tree parsing, the XML DOM tree traversal, or the SQLite insertions which are causing the biggest problem.

If DOM tree parsing (or even traversal) is the issue, you should seriously consider switching to one of libxml2's more efficient XML parsing tools: xmlTextReader (the XML pull api) or SAX (the XML push api). I recommend xmlTextReader:

http://xmlsoft.org/xmlreader.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜