0

My goal is to make XML binding in javascript. Although this is uncommon, I need this for a Thunderbird plugin. I wish to make in javascript (XPCOM has no longer java support). So this isn't for serializing and using JSON. I really need XML manipulation in Javascript. I don't mind if the scripts are heavily sized.

Ideally, I want to reuse java code (because I've got a lot of java code done and also because I have no clue of JS :s ). So I have been looking on how to deal with this in GWT with JAXB : GWT and a jaxb objects

Unfortunately, the gwtjaxb project seems to only deal with marshalling and I need both, Marshalling and Unmarshalling, in gwt client code. Am I wrong?

I've also considered Pitiri: GWT XML (xml-object-mapping)

And also using Errai in gwt to map to JSON and then with Jsonix (via JSNI) from JSON to XML and vice versa: Is there a JavaScript API for XML binding - analog to JAXB for Java?

POJO <=> JSON <=> XML  

But this seems tedious.

Does someone have any experience or clue on this?

Thanks!

Community
  • 1
  • 1
Dom
  • 27
  • 6
  • what about this: http://stackoverflow.com/questions/1773550/convert-xml-to-json-and-back-using-javascript ? (Josh Stodola answer) – Proqb Aug 20 '15 at 10:10

1 Answers1

0

Author of Jsonix here. I'll just address the question if Jsonix is of help here or not.

Jsonix suits the JSON <=> XML task, it's neatly bidirectional and has nice features of being type and structure-strict.

But you need mappings to make the conversions. This is normally not a big deal if you have and XML Schema to start with. If you don't, you'd have to write them manually which can be somewhat problematic. At the moment, there's no way to generate these mappings from Java code (as I understand this is what you need). It would be possible to implement (and not problematic at all), but it just isn't there at the moment.

By the way, do you need POJO <=> JSON <=> XML or would POJO <=> JSON plus POJO <=> XML work as well? I think the latter should be possible with JAXB/Jackson combo.

lexicore
  • 42,748
  • 17
  • 132
  • 221
  • Hi thanks for your answer. Indeed I need structure-strict conversion from classes to XML and back from XML to classes. I know JAXB can do this but I want to make the GWT library convert my code to JavaScript and JAXB can't be converted. I haven't found any other library to directly bind to XML. I saw that your JSONIX library works in JS and deals with JSON to XML. So I thought of making my GWT code bind to JSON and then call JSONIX to make the last step to XML. Do you think it is a viable way of doing things ? Thanks – Dom Aug 24 '15 at 08:35
  • Indeed, I already have the xml schemas. So this is no issue for me. I still need a structure-strict bidirectional conversion from POJO to JSON (has to be GWT convertible). I thought of "Errai" but I haven't found much feedback... – Dom Aug 24 '15 at 08:39
  • @Dom I'm not very much into GWT so I can't give much advice on that. But what I know for sure is that Jsonix can reliably convert between XML and JSON on the client. In both directions, type-strict and structure-strict. I'd suggest trying the [Purchase Order](https://github.com/highsource/jsonix/wiki/Working-Example) example to see if it's something for you. See [this explanation](http://stackoverflow.com/questions/83405/xml-parser-for-javascript/26957382#26957382) as well - but consider and decide for yourself. – lexicore Aug 24 '15 at 10:23