Search code examples
namespacesprefixjsonix

jsonix - How to create an element with prefix and without namespace?


I'm required to send an XML with the following elements:

<return>
    <getrooms>true</getrooms>
    <filters xmlns:a="http://some.com/xsd/atomicCondition" xmlns:c="http://some.com/xsd/complexCondition">
        <city></city>
        <country></country>
        <c:condition>
            <a:condition>
                <fieldname>fieldName</fieldname>
                <fieldtest>fieldTest</fieldtest>
                <fieldvalues>
                    <fieldvalue>fieldValue</fieldvalue>
                </fieldvalues>
            </a:condition>
            <operator>operator</operator>
            <a:condition>
                <fieldname>fieldName</fieldname>
                <fieldtest>fieldTest</fieldtest>
                <fieldvalues>
                    <fieldvalue>fieldValue</fieldvalue>
                 </fieldvalues>
            </a:condition>
         </c:condition>
    </filters>
    <resultsperpage></resultsperpage>
    <page></page>
</return>

I'm having difficulty forming the "c:condition" and "a:condition" Qname using Jsonix. Both Qname contains a Prefix but don't have the namespace.

My current code is:

{
    type: 'element',
    name: 'ccondition',
    elementName: {
        localPart: 'condition',
        prefix: 'c',
        namespaceURI: 'c'
    },
    typeInfo: 'DOXML.ComplexCondition'
},

This will result in the following:

<c:condition xmlns:c="c">

Anyone knows how to use Jsonix to generate the required Qname - "c:condition" that is without the namespaceURI?


Solution

  • In your example, the prefix c is actually bound to the namespace http://some.com/xsd/complexCondition in this line:

    <filters xmlns:a="http://some.com/xsd/atomicCondition" xmlns:c="http://some.com/xsd/complexCondition">

    Both you prefixes a und c are bound to non-empty namespaces within the scope of the filters element.

    So you should actually do:

    { type: 'element', name: 'ccondition', elementName: { localPart: 'condition', prefix: 'c', namespaceURI: 'http://some.com/xsd/complexCondition' }, typeInfo: 'DOXML.ComplexCondition' }

    I think you should be able to map to the empty namespace with namespaceURI: '', but this is not what you need in your case, if I see it correctly.