问题描述
我正在尝试解析带有多个NSXMLParserDelegate解析器的xml树文件,但是我遇到了下一个问题.
I'm trying to parse an xml tree file whith multiple NSXMLParserDelegate parsers but I'm getting in the next issue.
我的XML结构就是这样.
My XML structure is something like that.
<Object1>
<Name>Ricky</Name>
<Surname>Woodstock</Surname>
<Adress>
<City>Los Angeles</City>
<State>California</State>
<Country>USA</Country>
</Adress>
<Items>
<Item>
<Id>1</Id>
<Description>Sports Bag</Description>
<Price>13.45</Price>
</Item>
<Item>
<Id>2</Id>
<Description>Baseball Cap</Description>
<Price>6.90</Price>
</Item>
</Items>
<Total>20.15</Total>
</Object1>
我的问题是,当我更改委托时,它开始不在顶级标签中进行解析,而是开始在第一个嵌套标签上进行解析.
And my Issue is that when I changes delegates, it starts parsing not in top-level tag, instead it begins parsing on the first nested tag.
例如.
-
我开始使用可解析元素的XMLObject解析器解析XML
I begin parsing XML wih XMLObject parser which parses element
当到达Adresss标记时,我将委托设置为XMLAdressParser(并将XMLAdressParser的父对象设置为self以返回),但是XMLAdressParser开始在标记上进行解析.
When it reaches Adresss tag I set delegate to XMLAdressParser (and set XMLAdressParser's parent to self for returning) but XMLAdressParser begins parsing on tag.
几乎包含Items和Item标签.
And almost with Items and Item tags.
我认为这是解析器定义的正常原因,但这是问题所在:
I think it's normal cause of a Parser definition, but that's the question:
有没有办法让委托像第一个一样开始在对应的标记中进行解析?
Is there any way for the delegate to start parsing in correspondint tag, like first one?
在此先感谢您的帮助.
塞尔吉奥
推荐答案
我建议不要使用多个委托,而应该使用单个委托并让它在您认为合适的情况下分发工作.
Rather than using multiple delegates I suggest using a single delegate and having it distribute the work as you feel appropriate.
这篇关于具有多个委托的NSXMLParser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!