使用NSXMLParser委托来解析两个文件 [英] Use NSXMLParser delegate to parse two files
问题描述
我需要在同一个视图控制器中解析两个完全不同的XML数据文件,因此我想知道是否可以仅针对一个实例更改NSXMLPaser委托方法的名称.
I need to parse two completely different XML data files in the same view controller, so I would like to know if it is possible to change the name of NSXMLPaser delegate methods, just for one instance.
推荐答案
不,您不能.而且没有必要这样做.
通过检查委托方法的第一个参数,只需区分解析器即可.
例如:
No you can't. And there is no need to do that.
Simply differenciante the parsers by checking the first parameter of delegate methods.
For example :
-(void)parserDidEndDocument:(NSXMLParser *)parser;
有关的解析器始终作为第一个参数传递.
The concerned parser is always passed as the first argument.
另一种解决方案是为两个解析器提供不同的委托,因此您始终知道要关注哪个解析器.
Another solution is to give the two parsers different delegates, so you always know which parser is concerned.
这篇关于使用NSXMLParser委托来解析两个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!