使用 XSD.exe,我可以轻松地从 XSD 文件派生 C# 或 VB.NET 类。是否有可用于将 XSD 转换为 JavaScript 的工具?
问问题
6886 次
1 回答
5
免责声明:我是Jsonix的作者,这是一个用于 XML<->JS 转换的开源库。
使用 Jsonix,您可以将架构编译为 JavaScript 映射,然后在 JavaScript 代码中编组/解组 XML。这是一个例子:
// 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);
});
于 2011-06-10T16:39:53.567 回答