1

I have a problem here, and it goes like this;

I have 50 Classes (an XML parser) for different responses/message types, to illustrate a sample of the existing XML message received see below:

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

Until recently, a requirement to allow multi-transaction messages be received has been imposed thus the recent message will now look like the one below:

<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>

What I want to know, is what approach will be more efficient:

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)

Also, take note that the element nodes can variably change during each responses. so the child nodes can be 1 to N ( where N is the limit ).

Are there any viable solution/s to this kind of scenario? I do not wish to re-write the existing code (one of the programmers virtues) but if its the only way, then so be it.

I am implementing this on iPhone using Objective-C

TIA

4

0 回答 0