且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iOS:结合使用SAX和DOM解析

更新时间:2023-08-19 13:11:36

通常,您的方法对我来说还不错.如果您的解决方案为您工作而不会出现性能问题,那么我就不会太担心字符串处理.如果需要,您可以对应用程序进行配置文件,以了解这样做浪费了多少CPU时间.

In general your approach sounds fine to me. If your solution is working for you without performance problems then I wouldn't be too worried about the string handling. If you want to you can profile your application to see how much CPU time is wasted by this.

如果您想做一些更优化的事情,可以尝试找到一个SAX解析器,该解析器为您提供原始缓冲区的字节偏移量,并将其与DOM解析器结合使用,该解析器使您可以使用非空终止的C字符串.我相信这意味着您必须切换到C或C ++库.我已经使用 rapidxml 进行类似于您尝试的操作(嵌入大文件中的xml块).

If you want to do something slightly more optimized, you could try to find a SAX parser that gives you the byte offsets of the original buffer and combine this with a DOM parser that lets you work with non null-terminated C strings. I would believe this means you have to switch to a C or maybe C++ library. I have used rapidxml for something vaguely similar to what you are trying (xml chunks embedded in huge file).