You might try something like

<collection create-type=”java.util.ArrayList” field=”childElems”>
<structure name=”ChildElem”><value name=”ChildElemValue” style=”attribute” 
type=”java.lang.String”/></structure>
</collection>

That is, the collection has no name, in particular, but is composed of a bunch 
of ‘ChildElem’ elements.  The ‘ChildElem’ elements, themselves, don’t have any 
special binding to an object, but are just structural XML, containing an 
attribute named “ChildElemValue” which is a String.

Not absolutely sure this will work right, but it might.


From: Bhowmik, Bindul [mailto:bindulbhow...@gmail.com]
Sent: Friday, August 29, 2014 3:43 PM
To: jibx-users@lists.sourceforge.net
Subject: [jibx-users] Unmarshalling attributes of child element to a collection

​Hello,

​
​I am trying to use JiBX to parse a larger XML, which includes a structure 
similar to the ones noted below:

Schema:
<xs:complexType name="Parent">
    <xs:sequence>
        <xs:element name="ChildElem" maxOccurs="unbounded">
            <xs:complexType>
                <xs:attribute name="ChildElemValue" type="xs:string" 
use="required"/>
            </xs:complexType>
        </xs:element>
    </xs:sequence>
    <xs:attribute name="Child1" type="xs:string"/>
    <xs:attribute name="Child2" type="xs:int"/>
</xs:complexType>
Sample Value:
<Parent Child1="AttrVal" Child2="999">
    <ChildElem ChildElemValue="SomeVal"/>
    <ChildElem ChildElemValue="SomeVal2"/>
</Parent>​

The equivalent class I am trying to map this to is:
public class Parent {
    private String child1;
    private int Child2;
    private List<String> childElems;
}
I am trying to write a mapping for marshalling and unmarshalling, without 
requiring a class to represent the ChildElem, because all it will ever have is 
a string in the ChildElemValue attribute.
I am open to (but not experienced with) custom Marshaller / Unmarshaller, and 
if so, I would like to reuse them as much as possible, as there are similar 
structures as above (with different element / attribute names) all over the 
project.

Any help or direction in accomplishing this would be greatly appreciated.

Regards,
Bindul​



________________________________
This message and its contents (to include attachments) are the property of 
National Health Systems, Inc. and may contain confidential and proprietary 
information. This email and any files transmitted with it are intended solely 
for the use of the individual or entity to whom they are addressed. You are 
hereby notified that any unauthorized disclosure, copying, or distribution of 
this message, or the taking of any unauthorized action based on information 
contained herein is strictly prohibited. Unauthorized use of information 
contained herein may subject you to civil and criminal prosecution and 
penalties. If you are not the intended recipient, you should delete this 
message immediately and notify the sender immediately by telephone or by 
replying to this transmission.
------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to