TouchXML - CXMLDocument 对象初始化失败
我被一些 TouchXML 代码困住了。请帮忙。
我有以下代码从 xml webservice 获取数据:
NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"String data: %@ \n", data);
//Do the parsing
CXMLDocument *document = [[[CXMLDocument alloc] initWithData:urlData encoding:NSUTF8StringEncoding options:0 error:&error] autorelease];
NSLog (@"Document :%@ \n",[document stringValue]);
字符串数据确实具有来自服务的内容,但为什么 CXMLDocument 对象不包含任何内容?有人可以告诉我为什么吗?
2009-12-30 18:21:59.467 MyAdvancedBlog[3425:207] String data: <?xml version="1.0" encoding="utf-8"?>
<Post xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<IdPostazione>42</IdPostazione>
<StringID>HOANG</StringID>
<Name>CASSA2</Name>
<TerminalValid>true</TerminalValid>
<NeedSession>false</NeedSession>
</Post>
2009-12-30 18:21:59.469 MyAdvancedBlog[3425:207] Document :(null)
I am stuck with some TouchXML code. Please help.
I have the following code to get the data from an xml webservice:
NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"String data: %@ \n", data);
//Do the parsing
CXMLDocument *document = [[[CXMLDocument alloc] initWithData:urlData encoding:NSUTF8StringEncoding options:0 error:&error] autorelease];
NSLog (@"Document :%@ \n",[document stringValue]);
The string data does have the content from the service, but how come the CXMLDocument object does not contain anything? Someone can tell me why?
2009-12-30 18:21:59.467 MyAdvancedBlog[3425:207] String data: <?xml version="1.0" encoding="utf-8"?>
<Post xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<IdPostazione>42</IdPostazione>
<StringID>HOANG</StringID>
<Name>CASSA2</Name>
<TerminalValid>true</TerminalValid>
<NeedSession>false</NeedSession>
</Post>
2009-12-30 18:21:59.469 MyAdvancedBlog[3425:207] Document :(null)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TouchXML 文档 指出
CXMLDocument
的行为应类似于NSXMLDocument
。因此,initWithData:options:error:
的参考可能会有所帮助。它表示如果不成功,结果将为
nil
,并且error
将包含更多信息。是nil
吗?您可以暂时考虑使用 NSXMLDocument,看看它们的行为是否真的相同。如果没有,请使用 TouchXML 提交错误。
您还可以使用
initWithXMLString:options:error:
以及您已解码的字符串。编辑:甚至更好。这是 使用
NSXMLDocument
的示例代码。理论上,它也应该适用于CXMLDocument
。TouchXML's documentation says that
CXMLDocument
should act just likeNSXMLDocument
. So, the reference forinitWithData:options:error:
might help.It says the result will be
nil
if it's unsuccessful, anderror
will then contain more info. Is itnil
?You might consider using
NSXMLDocument
for the moment, and see if they really do act the same. If they don't, file a bug with TouchXML.You could also use
initWithXMLString:options:error:
along with that string you already decoded.Edit: Even better. Here's example code for using
NSXMLDocument
. In theory, it should work forCXMLDocument
as well.