codingKit
codingKit

Reputation: 13

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?

Upvotes: 1

Views: 309

Answers (1)

lexicore
lexicore

Reputation: 43671

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.

Upvotes: 0

Related Questions