Skip to content

Configuring Namespace Prefixes

Alexey Valikov edited this page Feb 27, 2015 · 2 revisions

Configuring Namespace Prefixes

XML supports namespaces and Jsonix is namespace-aware.

When Jsonix generates or parses XML, it will take namespaces into an account. Elements and attributes will be generated or parsed basen on their fully qualified names, together with their namespace URIs.

From the technical point of view, the prefix used for some namespace is not meaningful. However, for humans it is often better to use some estabilished namespace, like xlink for http://www.w3.org/1999/xlink.

You can configure known namespace URI/prefix mappings using the namespacePrefixes option when creating the Jsonix context.

Example:

// Create a Jsonix context
var context = new Jsonix.Context(mappings, {
    namespacePrefixes: {
        "http://www.opengis.net/cat/csw/2.0.2": "csw",
        "http://www.opengis.net/ogc": "ogc",
        "http://www.opengis.net/gml": "gml"
    }
});

namespacePrefixes is a map of namespace/prefix pairs. Every time Jsonix would need to determine a prefix for a certain namespace, it will first consult this configuration. During marshalling these namespace prefixes will also be eagerly declared on the root element.