Dennis,
I want to thank you for your suggestions. I found a solution for my problem using multiple namespaces for a single tag. The xml that I work with, financial products, almost all have this requirement of having multiple namespaces throughout. Just in case anyone else was experiencing a similar issue, I wanted to provide a snippet of what I found to resolve the issue for my case, enabling me to marshal and unmarshal successfully.
snippet from binding file:
<binding>
<!-- **** namespace definitions ****-->
<namespace uri="http://www.fpml.org/2005/FpML-4-2" default="elements"/>
<namespace uri="http://www.w3.org/2001/XMLSchema-instance" prefix="xsi"/>
<!-- ******************* FpML ************************-->
<mapping name="FpML" class="FpML">
<value style="attribute" name="version" field="version"/>
<value style="attribute" ns="http://www.w3.org/2001/XMLSchema-instance" name="schemaLocation" field="schemaLocation"/>
<value style="attribute" ns="http://www.w3.org/2001/XMLSchema-instance" name="type" field="type"/>
. . .
</mapping>
</binding>
snippet from xml:
<?xml version="1.0" encoding="UTF-8"?>
<FpML xmlns="http://www.fpml.org/2005/FpML-4-2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="4-2"
xsi:schemaLocation="http://www.xyz.com/2005 ../../xsd/1-1-6-EXP.xsd"
xsi:type="xyz:CreateTradeRequest"/>
. . .
Best regards,
Simone
| Dennis Sosnoski <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED] 08/22/2005 02:37 AM
|
To: [email protected] cc: Subject: Re: [jibx-users] Multiple Default Namespaces for one tag? |
Hi Simone,
You want to change the prefix on the first <namespace> definition (the
one right after the <binding> element) - or maybe just take this one out
completely, since I don't see anywhere you use it. The problem is that
you try to reuse the same prefix later; this is actually okay from an
XML standpoint, but JiBX doesn't support it (and there's no reason to,
since prefixes are essentially arbitrary).
- Dennis
[EMAIL PROTECTED] wrote:
>
> Thank you for your help Dennis and Andreas!
>
> I tried the modified binding that you provided and for some reason I
> got a JiBXException of, "Namespace prefix conflict ". Do you see
> something that I have overlooked?
>
> <binding>
> <namespace uri="http://www.sosnoski.com/ns1_2" prefix="xsi"
> default="none"/>
> <mapping name="customer" class="example9.Customer">
> <namespace uri="http://www.sosnoski.com/ns1" default="elements"/>
> <namespace uri="http://www.w3.org/2001/XMLSchema-instance"
> default="none" prefix="xsi"/>
> <value style="attribute"
> ns="http://www.w3.org/2001/XMLSchema-instance" name="schemaLocation"
> get-method="getSchemaLocation" set-method="setSchemaLocation"
> usage="optional"/>
> <structure field="person"/>
> <value name="street" field="street"/>
> <value name="city" field="city"/>
> <value name="state" field="state"/>
> <value name="zip" field="zip"/>
> <value name="phone" style="attribute" field="phone"/>
> </mapping>
> <mapping name="person" class="example9.Person">
> <namespace prefix="ns2" uri="http://www.sosnoski.com/ns2"
> default="all"/>
> <value name="cust-num" style="attribute" field="customerNumber"/>
> <value name="first-name" field="firstName"/>
> <value name="last-name" field="lastName"/>
> </mapping>
> </binding>
>
>
> the sample xml:
> <customer phone="888.555.1234" xmlns="http://www.sosnoski.com/ns1"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://www.sosnoski.com/ns1_2
> http://www.sosnoski.com/ns1.xsd">
> <ns2:person ns2:cust-num="123456789"
> xmlns:ns2="http://www.sosnoski.com/ns2">
> <ns2:first-name>John</ns2:first-name>
> <ns2:last-name>Smith</ns2:last-name>
> </ns2:person>
> <street>12345 Happy Lane</street>
> <city>Plunk</city>
> <state>WA</state>
> <zip>98059</zip>
> </customer>
>
> the exception:
> org.jibx.runtime.JiBXException: Namespace prefix conflict at
> org.jibx.binding.def.DefinitionContext.addNamespace(DefinitionContex.java:146)
>
> at
> org.jibx.binding.def.BindingBuilder.unmarshalNamespaces(BindingBuildr.java:901)
>
> at
> org.jibx.binding.def.BindingBuilder.unmarshalMapping(BindingBuilder.ava:1564)
>
> at
> org.jibx.binding.def.BindingBuilder.unmarshalMappings(BindingBuilderjava:973)
>
> at
> org.jibx.binding.def.BindingBuilder.unmarshalBindingDefinition(BindigBuilder.java:1750)
>
> at org.jibx.binding.Utility.loadBinding(Utility.java:309)
> at org.jibx.binding.Utility.loadFileBinding(Utility.java:389)
> at org.jibx.binding.Compile.compile(Compile.java:294)
> at org.jibx.binding.Compile.main(Compile.java:382)
>
>
> Many thanks in advance for your input/suggestions!
>
> Simone
>
This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates.
