With XSD.exe I can easily derive a C# or VB.NET class from a XSD file. Is there a tool available to convert XSD to JavaScript?
Asked
Active
Viewed 8,181 times
4
-
I think it is less necessary to do something like this for a weakly-typed language. – jiggy Jun 10 '11 at 15:59
1 Answers
5
Disclaimer: I am the author of Jsonix, an open-source library for XML<->JS conversion.
With Jsonix you can compile your schema into JavaScript mappings and then marshall/unmarshall XML in your JavaScript code. Here's an example:
// First we construct a Jsonix context - a factory for unmarshaller (parser)
// and marshaller (serializer)
var context = new Jsonix.Context([ PO ]);
// Then we create an unmarshaller
var unmarshaller = context.createUnmarshaller();
// Unmarshal an object from the XML retrieved from the URL
unmarshaller.unmarshalURL('/org/hisrc/jsonix/samples/po/test/po-0.xml',
// This callback function will be provided with the result
// of the unmarshalling
function(result) {
// We just check that we get the values we expect
assertEquals('Alice Smith', result.value.shipTo.name);
assertEquals('Baby Monitor', result.value.item[1].productName);
});
-
lexicore: thanks for the tip. I have tried xsd with the "JS" option, the syntax is a different to JavaScript with the private declarations etc. I haven't tried Jsonix, will try this – G33kKahuna Jun 10 '11 at 18:04