Hi Günther,

The problem with this binding is that in order to have the <collection> 
as a child of the <mapping> with flexible='true' you need to define a 
name for the collection - a wrapper element around the items in the 
collection. This is needed so that JiBX can generate code that "knows" 
the possible element names to be handled and can ignore the rest, as 
appropriate for flexible='true'.

If you're using an XML representation that you can't control, and that 
representation doesn't have any wrapper element, I realize you can't add 
a name on the collection. In this case the best you can do is probably 
to use a custom marshaller/unmarshaller for the Customer class. You can 
still define a <mapping> for the Address class, and your custom code for 
Customer can invoke this as needed. See the tutorial on this for more 
details: http://jibx.sourceforge.net/tutorial/binding-custom.html#marunmar

  - Dennis

Dennis M. Sosnoski
SOA and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117



Günther Wieser wrote:
> hi,
>
> i'm a total newbie to jixb so this might be more a question of 
> understanding than of a problem. i went through the mailing list 
> archive, found some interresting things but nothing solved my 
> problems, so i'm ending up here ;-)
>
> think about the following binding:
> <?xml version="1.0" encoding="ISO-8859-2"?>
> <binding>
> <mapping name="customer" class="data.Customer" flexible="true" 
> ordered="false" allow-repeats="true">
> <value name="id" set-method="setJiXBId" get-method="getJiXBId"/>
> <value name="first" set-method="setJiXBFirstName" 
> get-method="getJiXBFirstName"/>
> <value name="last" set-method="setJiXBLastName" 
> get-method="getJiXBLastName"/>
> <collection field="addresses" flexible="true" ordered="false">
> <structure name="address" type="data.Address" flexible="true" 
> ordered="false">
> <value name="id" set-method="setJiXBId" get-method="getJiXBId"/>
> <value name="street" set-method="setJiXBStreet" 
> get-method="getJiXBStreet" usage="optional"/>
> <value name="city" set-method="setJiXBCity" get-method="getJiXBCity" 
> usage="optional"/>
> </structure>
>   </collection> 
> </mapping>
> </binding>
>
> this does not compile, jixb complains about the following:
>      [bind] Error: All child components must define element names for 
> flexible='true'; on collection element at (line 7, col 66, in 
> C:/JavaDev322/JiXB Test/src/customer_binding.xml)
>      [bind] Error running binding compiler
>      [bind] org.jibx.runtime.JiBXException: Binding C:/JavaDev322/JiXB 
> Test/src/customer_binding.xml is unusable because of validation errors
>
> problem is: we get XML data that could have more elements than we 
> expect, but we simply do not need to take care of this. but of course 
> we must get jixb to ignore these during runtime.
>
> i've tried several other ways to solve this:
>
> i removed the collection element and added getters and setters to the 
> structure (the setter simply adds an "address" to the list) and set 
> "allow-repeats" to true.
> with this approach i ended up with a very strange situation. giving 
> the following input, i received a strange result.
> input:
> <?xml version="1.0" encoding="ISO-8859-2"?>
> <customer>
> <id>1234</id>
> <first>Heinz</first>
> <last>Prueller</last>
> <asdasd>asasd</asdasd>
> <address>
> <id>111</id>
> <street>Daham 1</street>
> <city>1110 Wien</city>
> </address>
> <address>
> <id>222</id>
> <street>Daham 2</street>
> <city>2220 Wien</city>
> <kasperl>asdasd</kasperl>
> </address>
> <address>
> <id>333</id>
> <street>Daham 3</street>
> <city>3330 Wien</city>
> </address>
> </customer>
>
> outcome:
> Adding [EMAIL PROTECTED] 1][city=1110 
> Wien]]
> Adding [EMAIL PROTECTED] 2][city=2220 
> Wien]]
> Adding [EMAIL PROTECTED] 3][city=3330 
> Wien]]
> Result: 
> [EMAIL PROTECTED]@2e7263[[id=333][street=Daham 
> 3][city=3330 [EMAIL PROTECTED] 
> 3][city=3330 [EMAIL PROTECTED] 
> 3][city=3330 Wien]]]]]
>
> as you can see, the three address object were passed to my 
> addAddress() method with the correct values, but the final collection 
> holds three address objects which all hold the same data!!!! weird!
>
> so my question is:
>
> how can i define a binding that either uses collections or can deal 
> with collections, but allows "unknown" XML elements to exist in the 
> data coming in without getting exceptions during runtime?
>
> br,
> guenther
>
> -- 
> Günther Wieser
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >>  http://get.splunk.com/
> ------------------------------------------------------------------------
>
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users
>   

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to