gpt4 book ai didi

javascript - XSD 到 JavaScript 类的转换

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:38:15 25 4
gpt4 key购买 nike

使用 XSD.exe,我可以轻松地从 XSD 文件派生 C# 或 VB.NET 类。是否有可用于将 XSD 转换为 JavaScript 的工具?

最佳答案

  • 试试 xsd/language:JS(参见 here)。

  • 尝试 Jsonix .

免责声明:我是 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);
});

关于javascript - XSD 到 JavaScript 类的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6308599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com