want to have same XML tag multiple times.

70 views
Skip to first unread message

Jyoti Balabantaray

unread,
Aug 1, 2013, 1:11:32 AM8/1/13
to fle...@googlegroups.com
Hi,
I want to have same tag multiple times in my generated XML.
It's similar like multiple <property> tag inside one <bean> tag.
ex - 

<bean class="com.ff.SubSection" id="id1">
  <property ref="posPayItemIndex" name="index"/>
  <property ref="crlfAssembler" name="assembler"/>

 <property name="fields">
    <list>
      <bean class="com.ep.ff.transfer.format.NumberField" id="checkNumberField">
        <property value="10" name="length"/>
        <property value="amount" name="target"/>
      </bean>
      <bean class="com.ep.ff.transfer.format.NumberField" id="checkAmountField">
        <property value="10" name="length"/>
        <property value="amount" name="target"/>
      </bean>
    </list>
  </property>
</bean>
 I kind of achieved this by the below way.

[XmlAttribute (alias="id")]
public var id : String;
[XmlAttribute (alias="class")]
public var clsName : String;
[XmlElement(alias="property")]
public var property1 :PropertyXMLTag;
[XmlElement(alias="property")]
public var property2 :PropertyXMLTag;
[XmlElement(alias="property")]
public var property3 :PropertyXMLTag;
[XmlElement(alias="property")]
public var property4 :PropertyXMLTag;
[XmlElement(alias="property")]
public var property5 :PropertyXMLTag;
[XmlElement(alias="property")]

Here I have the limitation of max number of <property> tag since I have to define those as instance variable. Is there a way to make it dynamic depends upon the object creation.
Using list is not helping since it's creating one extra <list> tag before <property> tag. Kindly help.

Thanks,
Jyoti

Alexutz

unread,
Aug 1, 2013, 3:04:13 AM8/1/13
to fle...@googlegroups.com
I believe it will work if you use XmlArray with alias="*". Having separate variables for each property will cause teh exact limitation problem you're talkin about.
 
So make a property array and annotate it with
 
XmlArray[alias="*", type="YOUR_MEMBER_FULL_CLASS_NAME"]
 
and it should do the trick.
Let me know how it goes,
 
Alex

Jyoti Balabantaray

unread,
Aug 27, 2013, 5:21:52 AM8/27/13
to fle...@googlegroups.com
Thanks Alex. It helps.
Reply all
Reply to author
Forward
0 new messages