Is there a SaxParser that reads json and fires events so it looks like xml

后端 未结 3 937
花落未央
花落未央 2020-12-09 16:23

This would be great as it would allow my xml stuff to read json w/out any change except for the different sax parser.

3条回答
  •  余生分开走
    2020-12-09 17:16

    I think it is a bad idea to try treat JSON as if it was XML (which is what you are essentially asking); however, Jettison does just this. It exposes JSON content via Stax API (javax.xml.stream). And if you truly want SAX, writing wrapper from Stax to SAX is trivial as well (but not the other way around).

    I also think you might get better answers if you explained bit more what you are trying to achieve, beyond mechanisms you are hoping to use. For example, there are many data binding tools for both XML and JSON; and using such tools could hide lower level details much better than using abstraction meant for one to process the other.

提交回复
热议问题