javascriptjsonxmljsonix

Add custom xsi namespace with jsonix


How is it possible to add a custom xsi namespaces to a XML file with jsonix? We would like to achieve the following:

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

The best thing we could get was this using namespace prefixes:

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

Thanks!


Solution

  • Disclaimer: I am the author of Jsonix (well, you know).

    At the moment you can use the attribute property or the any attribute property to model xsi:schemaLocation, somethin like:

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

    Basically, just like any other normal attribute.

    However, I think xsi:schemaLocation should be supported on the Jsonix.Context level. This is not supported at the moment, but I think this is how it should look like:

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

    Similar to namespacePrefixes, but mapping namespace URIs onto schema locations.

    Please file an issue, if you'd like to have this feature.