javascript - 使用 jsonix 添加自定义 xsi 命名空间

标签 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">

谢谢!

最佳答案

免责声明:我是 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 ,如果您想拥有此功能。

关于javascript - 使用 jsonix 添加自定义 xsi 命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33158106/

相关文章:

javascript - 解析 Peg.JS 中的段落

javascript - DOM 结构到数组

python - 尝试加载多个json文件并合并为一个 Pandas 数据框

java - 如何在其他配置中重用 Maven 配置 XML 片段

javascript - 无法执行 "GET"xmlhttprequest - 错误

javascript - D3 : Links between spouses in a family tree

javascript - 数组到 JavaScript 字符串

json - 将Curl转换为Invoke-RestMethod

json - json.Unmarshal() 如何工作以及它如何存储在变量中?

Android约束布局,有重量的观点?