(XML解析)哪种设计模式或方法更有效

时间:2012-12-27 08:31:42

标签: ios xml parsing

我在这里遇到问题,就像这样;

我有50个不同的响应/消息类型的类(XML解析器),用于说明收到的现有XML消息的示例,如下所示:

<XML>
 <transaction>
  <messagetype>message</messagetype>
  <message>Blah, Blah, Blah</message>
 </transaction>
</XML>

直到最近,才收到允许接收多交易消息的要求,因此最近的消息现在看起来如下:

<XML>
 <transaction>
  <messagetype>message</messagetype>
  <message>Blah, Blah, Blah</message>
  <messagetype>notification</messagetype>
  <message>stopped</message>
  <messagetype>notification</messagetype>
  <message>started</message>
  <messagetype>alert</messagetype>
  <message>no service</message>
 </transaction>
</XML>

我想知道的是,哪种方法会更有效:

a. Create a new Class/Method to catch all type of request and traverse through all the XML element then store it to an array, then iterate through the loop and pass each array (xml element node) to their respective parsers.
b. Edit each Parser to accomodate the changes. (I seem to see this a very, very tedious job)
c. Create one big parser, putting all parsing stuffs there and then traverse using switch cases (this disregarding all the existing parsers)

另外,请注意元素节点可以在每个响应期间进行可变更改。所以子节点可以是1到N(其中N是限制)。

这种情况是否有可行的解决方案?我不想重写现有的代码(程序员的优点之一),但如果它是唯一的方法,那就这样吧。

我正在使用Objective-C

在iPhone上实现此功能

TIA

0 个答案:

没有答案
相关问题