How to parse different XML files using SAX on Android?

Here are the options as I see them: You can base the parsing capability based on the request (which should have some kind of context). If you know the request is Type A, then you know the response MUST use parser A You can have generic parser for all types, and branch what happens in the parser based on the first known tag or attribute that dictates what should be done Parse first, analyze after. Take all the response elements, and build object or object graphs out of them.

Pass those around, mutate them if need be for your application (don't try to edit xml - you're parsing it after all, and you want that to finish ASAP) Good luck!

Here are the options as I see them: You can base the parsing capability based on the request (which should have some kind of context). If you know the request is Type A, then you know the response MUST use parser A. You can have generic parser for all types, and branch what happens in the parser based on the first known tag or attribute that dictates what should be done.

Parse first, analyze after. Take all the response elements, and build object or object graphs out of them. Pass those around, mutate them if need be for your application (don't try to edit xml - you're parsing it after all, and you want that to finish ASAP).

Good luck!

Thanks for your answer. Your last option seems pretty interesting. Is there a way to achieve this using the SAX parser?

– Octavian Damiean Aug 27 '10 at 17:08 Sure, any start/end element event can be used to delineate object boundaries. – Nate Sep 2 '10 at 13:28.

The are all message response object, specify an attribute to indicate and object type in the xml response.

Only problem I have is that I can't modify the XML. – Octavian Damiean Aug 27 '10 at 12:39 then parse the xml for a specific differentiator and then branch the code on that value. – Aaron Saunders Aug 27 '10 at 13:47.

I send a XML file to a server as a request and get a XML file as response and all that as a background thread on Android. The XML request is serialized using various values. The XML response is then read by SAX and put into a list.

The whole request/response process happens in a background thread using the AsyncTask class. The problem is that I have different types of responses and I have no idea what approach to take to parse the response based on the request sent. How do I tell Android to use parser A based on request A and parser B based on request B?

EDIT: With different types of responses I mean the XML file looks different. It has different tags and different attributes.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions