Parsing XML by TBXML works on demo project, but it doesnt work in my real project

纵饮孤独 提交于 2019-12-11 04:09:32

问题


I'm really need help with parsing XML by TBXML. I created a demo project with a view has a button,when users press this button, I just call TBXML parsing function from another class. Im doing this to test my TBXMLParsing function works correctly or not. And it works pretty well in my demo project.

Finally, after I tested it, I copy and paste the function into my real project which has a button in first view, when I click on that button then it calls TBXMLParsing function. In other words, it is basically same as demo project. However, TBXMLParsing function doesn't work. It cant traverse thru all elements.

Do you have any ideas? Thanks for helping me.

Update: It is working if I simulate my app on real device, but it does not traverse thru the XML if I simulate it on simulator. It is so weird. However it does work on simulator if I create new project. Thus, there must be something that in my app that prevent parser XML.

Any ideas? Thank you

Update2:

NSData *data = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:@"http://dl.dropbox.com/u/37064335/ex.xml"]];

TBXML *tbxml = [[TBXML alloc] initWithXMLData:data];
[data release];
TBXMLElement *root = tbxml.rootXMLElement;

// if root element is valid
if (root) {
    NSLog(@"root =%s",root->name);

This is the part messed me up. I tested in demo app, Nslog root=GetUserAccountsRespond However in my app Nslog root= (nil-nothing printed out). Both projects are basically the same.


回答1:


Ok Here is solution for anyone that might has same problem as me. The problem was because when I Analyzed(shift+command+B) my project, xcode detected some "Semantic Issue" in TBXML.m. Then I just followed xcode's guide to change "=" to "==" in 3 places where it said "Process XML"(line258,311,and458) in TBXML.m. Thus TBXML does not work, because it cant process input XML. This problem drove me crazy for 2days. Thanks Tom Bradley for TBXML




回答2:


I would check that the XML document you are trying to parse is loaded correctly before passing it onto TBXML to decode. It sound to me like there is a problem with the loading code on the sim. Try outputting the file contents to the log to verify its correct.



来源:https://stackoverflow.com/questions/7919472/parsing-xml-by-tbxml-works-on-demo-project-but-it-doesnt-work-in-my-real-projec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!