【发布时间】:2014-12-09 09:48:08
【问题描述】:
我正在尝试使用来自XMLReader 的 XMLReader 来申请我的项目。 但我面临一个问题,我无法修复这个错误。这是我的实现。我为它设计了一个架构,包括流程和任务。每个流程都有单独的任务连接在一起。这里是转换任务,它从上一个任务接收一个 GDataXMlDocument 来处理下一个。
ResponseMessage* response = [super execute:request];
// To do task here
//
GDataXMLDocument *docObject = [[request getMessage:@"documentObject"] messageData];
NSString *content = [[docObject rootElement] XMLString];
NSLog(@"%@", [[docObject rootElement] XMLString]);
NSError *error = nil;
NSDictionary *dictionaryXML = [XMLReader dictionaryForXMLString:[[docObject rootElement] XMLString] error:&error];
还有一小部分 XML 对象:
<IposDocument xmlns="http://www.csc.com/integral/ipos-common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ipos-prospect="http://www.csc.com/integral/ipos-prospect"><Header><DocType/><DocId/><Version/><Validate/><IsValidateSuccess/><ClientDate/></Header><Data><ipos-prospect:Prospect vpms-suffix="Prospect"><ipos-prospect:Person vpms-suffix="Person"><ipos-prospect:FirstName vpms-suffix="FirstName" visible="1" mandatory="1" editable="1" default="" validate="" prefix="prospect.person.firstName."/><ipos-prospect:MiddleName vpms-suffix="MiddleName" visible="1" mandatory="0" editable="1" default="" validate="" prefix="prospect.person.middleName."/>
但是 XMLReader 不能解析这个对象并且总是返回 nil。我不知道为什么要调试它十几次。任何帮助表示赞赏。非常感谢。
【问题讨论】:
-
打印出你的错误,看看错误的内容。
-
不幸的是!没有错误,XMLReader 使用 NSXMLParser 进行 xml 解析。你知道,NSXMLParser 的解析函数返回 BOOL。它返回不!这就是为什么它可以在最后转换为 NSDictionary!
-
是的,但是你传入了一个错误指针——如果发生错误,你的错误对象应该有数据(通过 NSXMLParser 中的委托方法)——所以,如果你在
NSDictionary *dictionaryXML = [XMLReader dictionaryForXMLString:[[docObject rootElement] XMLString] error:&error];之后做NSLog(@"%@", [error userInfo]);吗? -
另外,你能显示你输入的 XML 吗?
-
是的!我试过了!但它返回 nil: 2014-12-09 17:56:53.959 iPOS[5116:70b] Error: (null)
标签: objective-c xml xml-parsing xmlreader