is it somehow possible to generate an empty object from an XML schema with JSONIX? I generally have problems creating new JS objects that fit to the XML schema. Thus, this would be really helpful. Any example would be very appreciated. I tried the following to create a new object. NodeType is a complex type name in this case.
{name: {localpart: nodeType}, value:{}};
Then I tried to fill values (I traverse through the schema mappings to find out all possible properties for each type). However, I get e.g. the following error that does not help me very much: Element [ELEMNAME] is not known in this context
If this is not possible, how do I in general create a new object that is supposed to be conform to the schema?
Thanks a lot for any idea!
EDIT: Okay to be more specific here an example:
"NodeType":{
"type":"object",
"title":"NodeType",
"properties":{
"id":{
"title":"id",
"allOf":[
{
"$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/string"
}
],
"propertyType":"attribute",
"attributeName":{
"localPart":"id",
"namespaceURI":""
}
},
"x":{
"title":"x",
"allOf":[
{
"$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/decimal"
}
],
"propertyType":"attribute",
"attributeName":{
"localPart":"x",
"namespaceURI":""
}
},
"y":{
"title":"y",
"allOf":[
{
"$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/decimal"
}
],
"propertyType":"attribute",
"attributeName":{
"localPart":"y",
"namespaceURI":""
}
}
This is one JSON Schema excerpt from my XSD file. What I want is an Object that looks like this:
{id:"", x: "", y: ""}
The goal is to marshall this object then to XML.
Disclaimer: I'm the author of Jsonix.
If I got your question right, you're asking, how could you construct a JS object that would be marshallable with Jsonix then.
The trick most people do is to take an XML "this is how it should look like", unmarshal it and the log JSON.stringify(myObject, null 2)
, something like that. Then you'll see how the appropriate JS should look like.
What you could also do is to generate an JSON Schema out of your XML Schema. This will get you a JSON Schema like this one, providing the complete description of the JSON you need for marshalling.
I also consider implementing something like generation of the TypeScript classes, but that's future music.
Update
I'm sorry, I'm still not quite sure what your question is. You've added an JSON Schema which defines a NodeType
complex type with a string id
and decimal x
and y
properties.
You're asking what an empty object for this would be. Well, an empty object for your complex type would be just {}
.
An object with values would be for instance {id:"someId", x: 4, y:2}
.
But in XML you can't marshal just a complex type, you marshal an element of complex type. Which is represented in a form of a { name: ..., value: ... }
. So you'd probably have something like:
{
"name": {
"namespaceURI": "uri",
"localPart": "root"
},
"value": {
"id" : "someId",
"x" : 4,
"y" : 2,
"TYPE_NAME": "NodeType"
}
}
Hope this helps.