问题描述
我真的需要通过TBXML解析XML的帮助.我创建了一个带有按钮的视图的演示项目,当用户按下该按钮时,我只是从另一个类调用TBXML解析函数.我这样做是为了测试我的TBXMLParsing函数是否正常工作.而且在我的演示项目中效果很好.
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.
最后,在测试之后,我将该函数复制并粘贴到我的真实项目中,该项目在第一个视图中具有一个按钮,当我单击该按钮然后调用TBXMLParsing函数时.换句话说,它与演示项目基本相同.但是,TBXMLParsing函数不起作用.它无法遍历所有元素.
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.
更新:如果我在真实设备上模拟我的应用程序,则可以正常工作,但是如果我在模拟器上模拟它,则不能遍历XML.太奇怪了但是,如果我创建新项目,它确实可以在模拟器上工作.因此,我的应用程序中一定有一些阻止解析器XML的东西.
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.
有什么想法吗?谢谢
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);
这部分让我感到困惑.我在演示应用中进行了测试,Nslog root = GetUserAccountsRespond但是,在我的应用程序Nslog中,root =(没有打印任何内容).这两个项目基本相同.
This is the part messed me up. I tested in demo app, Nslog root=GetUserAccountsRespondHowever in my app Nslog root= (nil-nothing printed out). Both projects are basically the same.
推荐答案
好,这是可能与我有相同问题的任何人的解决方案.问题是因为当我分析(shift + command + B)我的项目时,xcode在TBXML.m中检测到一些语义问题".然后,我只是按照xcode的指南在TBXML.m中的三个表示"Process XML"(line258、311和458)的地方将"="更改为"==".因此TBXML不起作用,因为它无法处理输入XML.这个问题使我疯狂了2天.感谢Tom Bradley提供的TBXML
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
这篇关于通过TBXML解析XML可以在演示项目上使用,但是在我的真实项目中却无法使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!