到目前为止,我已经导入了一个100KB的xml文件,一切正常.但是,不确定导入100MB xml需要多长时间.我会在一段时间内运行它.你觉得这种做法好吗?
谢谢
NSManagedobjectContext * context = [self managedobjectContext]; // Delete all documents NSFetchRequest * fetch = [[[NSFetchRequest alloc] init] autorelease]; [fetch setEntity:[NSEntityDescription entityForname:@"document" inManagedobjectContext:context]]; NSArray * result = [context executeFetchRequest:fetch error:nil]; for (ID basket in result) [context deleteObject:basket]; //Insert documents TBXML * tbxml = [[TBXML tbxmlWithXMLfile:@"categ_small.xml"] retain]; TBXMLElement * root = tbxml.rootXMLElement; TBXMLElement * doc = [TBXML childElementnamed:@"doc" parentElement:root]; do { TBXMLElement * IDDoc = [TBXML childElementnamed:@"ID" parentElement:doc]; TBXMLElement * TitleDoc = [TBXML childElementnamed:@"Title" parentElement:doc]; TBXMLElement * descriptionDoc = [TBXML childElementnamed:@"description" parentElement:doc]; TBXMLElement * time = [TBXML childElementnamed:@"time" parentElement:doc]; TBXMLElement * Tags = [TBXML childElementnamed:@"Tags" parentElement:doc]; TBXMLElement * geo = [TBXML childElementnamed:@"geo" parentElement:doc]; TBXMLElement * event = [TBXML childElementnamed:@"event" parentElement:doc]; TBXMLElement * user = [TBXML childElementnamed:@"user" parentElement:doc]; TBXMLElement * categ = [TBXML childElementnamed:@"categ" parentElement:doc]; NSManagedobject *newdocument = [NSEntityDescription insertNewObjectForEntityForname:@"document" inManagedobjectContext:context]; [newdocument setValue:[TBXML textForElement:IDDoc] forKey:@"IDDoc"]; [newdocument setValue:[TBXML textForElement:TitleDoc] forKey:@"TitleDoc"]; [newdocument setValue:[TBXML textForElement:descriptionDoc] forKey:@"descriptionDoc"]; [newdocument setValue:[TBXML textForElement:time] forKey:@"time"]; [newdocument setValue:[TBXML textForElement:Tags] forKey:@"Tags"]; [newdocument setValue:[TBXML textForElement:geo] forKey:@"geo"]; [newdocument setValue:[TBXML textForElement:event] forKey:@"event"]; [newdocument setValue:[TBXML textForElement:user] forKey:@"user"]; [newdocument setValue:[TBXML textForElement:categ] forKey:@"categ"]; } while ((doc = doc->nextSibling));
UPDATE
这是一次性 *** 作,仅在模拟器中运行,并且不会与最终应用程序一起部署.
>使用ruby或PHP编写转换器XML-> sqlite,或者如果您不是脚本语言的朋友,那么看看sqlite Manager它是一个管理sqlite数据库的firefox插件,它能够导入XML.
>按照本教程,预先填充核心数据以供发货:How To Preload/Import Existing Data
以上是内存溢出为你收集整理的objective-c – 将100MB XML文件导入iOS核心数据模型全部内容,希望文章能够帮你解决objective-c – 将100MB XML文件导入iOS核心数据模型所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)