Discussion:
[jibx-users] Multiple namespaces
Melchi, Pablo (GE Money, consultant)
2008-05-29 19:32:06 UTC
Permalink
Hello everybody.

Maybe this question has been posted before, so any link can be useful
for me.

I'm trying to unmarshall this XML using JiBX (it's a SOAP message)

<NS1:GetAllMemberItemsResponse xmlns:NS1="urn:OrdersIntf-IOrders"
xmlns:NS2="urn:uClasses">
<NS2:TKitItems id="1" xsi:type="NS2:TKitItems">
<Code xsi:type="xsd:int">1125</Code>
<Msg xsi:type="xsd:string">Could not find</Msg>
<Count xsi:type="xsd:int">0</Count>
<Items xsi:type="SOAP-ENC:Array"
SOAP-ENC:arrayType="NS2:TInventoryItem[0]" />
<PlanCode xsi:type="xsd:string"></PlanCode>
</NS2:TKitItems>
<return href="#1" />
</NS1:GetAllMemberItemsResponse>

I have defined this mapping:
<mapping name="GetAllMemberItemsResponse"
class="com.ge.binding.response.GetAllMemberItemsResponse">
<namespace uri="urn:OrdersIntf-IOrders" default="elements"/>
<structure field="kitItems"/>
</mapping>

<mapping name="TKitItems" class="com.ge.binding.response.TKitItems">
<namespace uri="urn:uClasses" default="elements" prefix="ns1"/>
<value name="Code" field="code"/>
</mapping>

I'm receiving this error when I try to unmarshall the message:
Expected "{urn:uClasses}Code" start tag, found "Code" start tag (line
-1, col -1, in SOAP-message)

Any idea of how to fix this?

I've been thinking about creating a third mapping with no namespace.

And I have also found that there is a workound by using custom
unmarshallers

Any other suggestions?

Thank you!
-Pablo Melchi
Dennis Sosnoski
2008-06-06 11:15:31 UTC
Permalink
Hi Pablo,

When you're working with mixed namespaces like this your best approach
is to avoid making any namespace a default. Instead just list the
namespaces in your binding (with <namespace> elements), then for each
element which uses one of the namespaces specify it directly on that
element using an ns="..." attribute. So in your example you'd need to
use ns="urn:OrdersIntf-IOrders" on the <mapping> for the
GetAllMemberItemsResponse element, and ns="urn:uClasses" on the
<mapping> or <structure> for the TKitItems element. For all the other
elements you'd just leave this attribute off, and with no default
namespace defined they'd be treated as having the empty namespace.

Doing things this way it's easy to use a single binding definition. The
<include>s approach is easier when you're working with namespaces that
apply to all the elements (the equivalent of
elementFormDefault="qualified" in a schema definition).

- Dennis
Post by Melchi, Pablo (GE Money, consultant)
Hello everybody.
Maybe this question has been posted before, so any link can be useful
for me.
I'm trying to unmarshall this XML using JiBX (it's a SOAP message)
<NS1:GetAllMemberItemsResponse xmlns:NS1="urn:OrdersIntf-IOrders"
xmlns:NS2="urn:uClasses">
<NS2:TKitItems id="1" xsi:type="NS2:TKitItems">
<Code xsi:type="xsd:int">1125</Code>
<Msg xsi:type="xsd:string">Could not find</Msg>
<Count xsi:type="xsd:int">0</Count>
<Items xsi:type="SOAP-ENC:Array"
SOAP-ENC:arrayType="NS2:TInventoryItem[0]" />
<PlanCode xsi:type="xsd:string"></PlanCode>
</NS2:TKitItems>
<return href="#1" />
</NS1:GetAllMemberItemsResponse>
<mapping name="GetAllMemberItemsResponse"
class="com.ge.binding.response.GetAllMemberItemsResponse">
<namespace uri="urn:OrdersIntf-IOrders" default="elements"/>
<structure field="kitItems"/>
</mapping>
<mapping name="TKitItems" class="com.ge.binding.response.TKitItems">
<namespace uri="urn:uClasses" default="elements" prefix="ns1"/>
<value name="Code" field="code"/>
</mapping>
Expected "{urn:uClasses}Code" start tag, found "Code" start tag (line
-1, col -1, in SOAP-message)
Any idea of how to fix this?
I've been thinking about creating a third mapping with no namespace.
And I have also found that there is a workound by using custom
unmarshallers
Any other suggestions?
Thank you!
-Pablo Melchi
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
jibx-users mailing list
https://lists.sourceforge.net/lists/listinfo/jibx-users
Loading...