How to parse different XML files using SAX on Android?

血红的双手。 提交于 2019-12-07 07:49:28

Here are the options as I see them:

  1. 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.
  2. 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.
  3. 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!

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

<response>
<error/>
<data type="A">
</data>
</response>

<response>
<error/>
<data type="B">
</data>
</response>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!