通过 TBXML 解析 XML 在演示项目中有效,但在我的真实项目中不起作用
我真的需要通过 TBXML 解析 XML 的帮助。 我创建了一个演示项目,其中的视图有一个按钮,当用户按下此按钮时,我只是从另一个类调用 TBXML 解析函数。 我这样做是为了测试我的 TBXMLParsing 函数是否正常工作。它在我的演示项目中运行得很好。
最后,在测试之后,我将该函数复制并粘贴到我的真实项目中,该项目在第一个视图中有一个按钮,当我单击该按钮时,它会调用 TBXMLParsing 函数。换句话说,它与演示项目基本相同。但是,TBXMLParsing 功能不起作用。它无法遍历所有元素。
你有什么想法吗?谢谢你帮助我。
更新: 如果我在真实设备上模拟我的应用程序,它就可以工作,但如果我在模拟器上模拟它,它不会遍历 XML。太奇怪了。但是,如果我创建新项目,它确实可以在模拟器上运行。因此,我的应用程序中一定存在阻止解析器 XML 的内容。
有什么想法吗?谢谢
更新2:
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= (nil-nothing 打印出来)。这两个项目基本相同。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,这是为可能遇到与我相同问题的任何人提供的解决方案。问题是因为当我分析(shift+command+B)我的项目时,xcode 在 TBXML.m 中检测到一些“语义问题”。然后我只是按照xcode的指南将TBXML.m中“处理XML”(第258,311和458行)的3个地方的“=”更改为“==”。因此 TBXML 不起作用,因为它无法处理输入 XML。这个问题让我抓狂了两天。感谢 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
我会检查您尝试解析的 XML 文档是否已正确加载,然后再将其传递到 TBXML 进行解码。在我看来,SIM 上的加载代码有问题。尝试将文件内容输出到日志以验证其正确性。
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.