XSD to JavaScript class conversion
With XSD.exe I can easily derive a C# or VB.NET class from a XSD file. Is there a tool availabl开发者_运维技巧e to convert XSD to JavaScript?
Try
xsd /language:JS
(see here).Try Jsonix.
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);
});
精彩评论