libxml2 解析器问题。如何处理来自服务器的错误消息?我该如何对待超时看门狗
我对相同的代码有一些疑问,
- 首先,
如果我返回的异常 XML 与我的应用程序阻止的对象类型不匹配,我该如何处理来自服务器的错误消息?
- 我如何对待网络超时(看门狗)
关于我的代码的任何其他建议将不胜感激。 我的代码:
xmlTextReaderPtr reader = xmlReaderForMemory([DecryResponse bytes], [DecryResponse length], NULL, NULL, (XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA | XML_PARSE_NOERROR | XML_PARSE_NOWARNING));
NSString * currentTagName =nil;
NSString * currentTagValue= nil;
char *temp = nil;
while (true) {
if(!xmlTextReaderRead(reader))break;
switch (xmlTextReaderNodeType(reader)) {
case XML_READER_TYPE_ELEMENT:
temp = (char *)xmlTextReaderConstName(reader);
currentTagName =[NSString stringWithCString:temp encoding:NSUTF8StringEncoding];
continue;
case XML_READER_TYPE_TEXT:
temp =(char *)xmlTextReaderConstValue(reader);
currentTagValue = [NSString stringWithCString:temp encoding:NSUTF8StringEncoding];
if ([currentTagName isEqual:@"Account"]) {
SW.Account =[currentTagValue intValue];}
if ([currentTagName isEqual:@"SessionNumber"]) {
SW.SessionNumber = currentTagValue; }
if ([currentTagName isEqual:@"OpCode"]) {
SW.OpCode = [currentTagValue intValue];}
default:continue;
}
}
I have a few questions about the same code sow
- first of all how do i treat error messages from the server
if i get a unusual XML returned that does not match the type of my object my app blockes;
- How do i treat network time out (the watchdogs)
Any other suggestion about my code will be appreciated.
My code:
xmlTextReaderPtr reader = xmlReaderForMemory([DecryResponse bytes], [DecryResponse length], NULL, NULL, (XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA | XML_PARSE_NOERROR | XML_PARSE_NOWARNING));
NSString * currentTagName =nil;
NSString * currentTagValue= nil;
char *temp = nil;
while (true) {
if(!xmlTextReaderRead(reader))break;
switch (xmlTextReaderNodeType(reader)) {
case XML_READER_TYPE_ELEMENT:
temp = (char *)xmlTextReaderConstName(reader);
currentTagName =[NSString stringWithCString:temp encoding:NSUTF8StringEncoding];
continue;
case XML_READER_TYPE_TEXT:
temp =(char *)xmlTextReaderConstValue(reader);
currentTagValue = [NSString stringWithCString:temp encoding:NSUTF8StringEncoding];
if ([currentTagName isEqual:@"Account"]) {
SW.Account =[currentTagValue intValue];}
if ([currentTagName isEqual:@"SessionNumber"]) {
SW.SessionNumber = currentTagValue; }
if ([currentTagName isEqual:@"OpCode"]) {
SW.OpCode = [currentTagValue intValue];}
default:continue;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论