In Java, we work a lot with JAXB2. Object<->XML mappings are defined as annotations in Java classes:
@XmlRootElement(name="usertask", namespace="urn:test")
public class UserTask
{
@XmlElement(namespace="urn:test")
public String getAssignee() { ... }
public void setAssignee(String assignee) { ... }
}
JAXB runtime can read these annotations and create unmarshaller to parse XML into an object instance or marshall an object into XML.
JAXB ships a schema compiler (XJC) which can generate annotated classes out of XML Schemas, which is another great feature.
Lately we've been working a lot with client-side JavaScript. An we also need XML processing there. For example, we need to parse WPS documents like this one. These documents also comply to different XML schemas (here's the WPS 1.0.0 schema for the sample XML). It would be great to work with JavaScript objects instead of XML, this saves really huge amount of effort. In some cases we can use JSON-based solutions like DWR, but in many cases we do have to process XML on the client-side.
My question is:
Is there some analog of JAXB for JavaScript?
Some tool which would compile an XML Schema into some XML<->object mapping and provide a runtime to convert between XML and JavaScript objects?
I could easily imagine mappings generated in a form like:
UserTask = new JSXML.XmlRootElement({
name: "usertask",
namespace: "urn:test",
properties: [
{
assignee: new JSXML.XmlElement({
name: "assignee",
namespace: "urn:test",
type: new JSXML.XSD.String()
})
}
]
});
And this should be pretty enough to build unmarshaller or marshaller.
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: