Is there a JavaScript API for XML binding - analog to JAXB for Java?

◇◆丶佛笑我妖孽 提交于 2019-11-30 04:52:50

How about JSON support for JAXB? Reuse your current JAXB annotated model classes but output JSON from your REST endpoints.

Current versions of Jersey support this (via the jersey-json module) with JSONJAXBContext.

You could also try Jackson's JAXB and JAX-RS support.

To date, I have found nothing similar to what I need. Therefore I've deсided to implement it myself. Here's the project page:

http://confluence.highsource.org/display/MISC/Jsonix

The project is hosted on GitHub:

https://github.com/highsource/jsonix/

I haven't tried this, so I'm not sure if it will work, but have you considered using GWT so that you can still use JAXB and write the whole app as a java app? I'm not sure if GWT supports JAXB (probably not), but there might be an alternative for xml parsing that it will support. If this works, you could automate the creation of your javascript models via gwt, and then include these into your app. Yes, it's a lot more cruft than you want, but beats having to write it from scratch.

What you can do is add a generic stylesheet definition: XSLT to your XML to convert them in JSON. eg: http://code.google.com/p/xml2json-xslt/

Handling XML with Javascript is a pain compared to JSON, especially cross browser.
The stylesheet will add a small overhead to your request. Either on the server or client side, you can choose, but you have to compare this to the code complexity and speed to parse and read the XML with Javascript on different browsers.

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