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
| Dennis Sosnoski <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED] 08/17/2005 08:55 AM
|
To: [EMAIL PROTECTED] cc: Subject: Re: [jibx-users] Multiple Default Namespaces for one tag? |
Thanks, Andreas! It's early morning here and I haven't had any caffeine
yet...
- Dennis
Andreas Brenk wrote:
>Some minor corrections: xs should read xsi and the schemaLocation
>attribute value is incomplete. The following validates:
>
><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
>http://www.sosnoski.com/ns1.xsd">
>
>See http://www.w3.org/TR/xmlschema-0/#schemaLocation
>
>Regards,
>Andreas
>
>Dennis Sosnoski wrote:
>
>
>>Hi Simone,
>>
>>Your sample XML output is not well-formed since it doesn't include the
>>declaration for the xs namespace. To be well-formed it should look like
>>this:
>>
>><customer phone="888.555.1234"
>> xmlns="http://www.sosnoski.com/ns1"
>> xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
>> xsi:schemaLocation="http://www.sosnoski.com/ns1_2">
>>
>>To do this in JiBX you'd want to use the binding:
>>
>><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="xs"/>
>> <value style="attribute"
>>ns="http://www.w3.org/2001/XMLSchema-instance" name="schemaLocation"
>>get-method="getSchemaLocation"
>> set-method="setSchemaLocation" usage="optional"/>
>> <structure field="person"/>
>> . . .
>> </mapping>
>></binding>
>>
>>JiBX should give an error when you try to use a namespace in the binding
>>that hasn't been defined - I'll add a check for that case.
>>
>> - Dennis
>>
>>[EMAIL PROTECTED] wrote:
>>
>>
>>
>>>Hello all. I stumbled upon an issue while marshalling my object into
>>>xml, and wanted to see if anyone has experienced my problem.
>>> Basically what I'm trying to do is the following:
>>>
>>>I need to define/declare more than one default namespace for a single
>>>mapping. This seems as though it would be a pretty common occurrence,
>>>however I have been unsuccessful. Here is a sample of the desired
>>>output:
>>>
>>><customer phone="888.555.1234"
>>> xmlns="http://www.sosnoski.com/ns1"
>>> xsi:schemaLocation="http://www.sosnoski.com/ns1_2">
>>>
>>>Here is a snippet of the binding that I am using:
>>><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"/>
>>> <value style="attribute" ns="http://www.sosnoski.com/ns1_2"
>>>name="schemaLocation" get-method="getSchemaLocation"
>>> set-method="setSchemaLocation" usage="optional"/>
>>> <structure field="person"/>
>>> . . .
>>> </mapping>
>>></binding>
>>>
>>>Here is the exception I receive:
>>> UnmarshallException: exception while unmarshalling
>>>UnmarshallException: Error unmarshalling XML: Error parsing document
>>>(line 2, col 162)
>>> XmlUnmarshaller.unmarshallXml(XmlUnmarshaller.java:80)
>>> TestFxSimpleOption.testDisconfactors(TestFxSimpleOption.java:219)
>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
>>>Source)
>>> at java.lang.reflect.Method.invoke(Unknown Source)
>>> at junit.framework.TestCase.runTest(TestCase.java:154)
>>> at junit.framework.TestCase.runBare(TestCase.java:127)
>>> at junit.framework.TestResult$1.protect(TestResult.java:106)
>>> at junit.framework.TestResult.runProtected(TestResult.java:124)
>>> at junit.framework.TestResult.run(TestResult.java:109)
>>> at junit.framework.TestCase.run(TestCase.java:118)
>>> at junit.framework.TestSuite.runTest(TestSuite.java:208)
>>> at junit.framework.TestSuite.run(TestSuite.java:203)
>>> at
>>>org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:436)
>>>
>>> at
>>>org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311)
>>>
>>> at
>>>org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
>>>
>>>
>>>with the output xml:
>>><customer phone="888.555.1234"
>>> xmlns="http://www.sosnoski.com/ns1"
>>> xmlns:xsi:schemaLocation="http://www.sosnoski.com/ns1_2">
>>>
>>>Any suggestions/input would be greatly appreciated!
>>>
>>>Many thanks!
>>>
>>>Simone
>>>
>>>
>
>
>
>
>-------------------------------------------------------
>SF.Net email is Sponsored by the Better Software Conference & EXPO
>September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
>Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
>Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
>_______________________________________________
>jibx-users mailing list
>[EMAIL PROTECTED]
>https://lists.sourceforge.net/lists/listinfo/jibx-users
>
>
>
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
jibx-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jibx-users
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.
