使用jsonix

时间:2015-10-15 20:37:53

标签: javascript json xml jsonix

如何使用jsonix将自定义xsi名称空间添加到XML文件?我们希望实现以下目标:

<network xsi:schemaLocation="http://example.com/XMLSchema ../../../Example/schema/Example.xsd">

我们可以得到的最好的事情是使用名称空间前缀:

<network xmlns:schemaLocation="http://example.com/XMLSchema ../../../Example/schema/Example.xsd">

谢谢!

1 个答案:

答案 0 :(得分:1)

免责声明:我是Jsonix的作者(嗯,你知道)。

目前,您可以使用attribute propertyany attribute property来模拟xsi:schemaLocation,例如:

{
    type: 'attribute',
    name: 'schemaLocation',
    attributeName : { localPart: 'schemaLocation', namespaceURI : 'http://www.w3.org/2001/XMLSchema-instance' }
    typeInfo: 'String'
}

基本上,就像任何其他普通属性一样。

但是,我认为xsi:schemaLocation级别应该支持Jsonix.Context。目前不支持此 ,但我认为这应该是这样的:

var context = new Jsonix.Context(mappings, {
    schemaLocations: {
        "http://example.com/XMLSchema": "../../../Example/schema/Example.xsd"
    }
});

namespacePrefixes类似,但将名称空间URI映射到架构位置。

如果您想要使用此功能,请file an issue

相关问题