Use the setWithCreate function to create a multiple instances of nested business object.
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="Parent">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="child" type="Child" maxOccurs="5"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Child">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="grandChild" type="GrandChild"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="GrandChild">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Note that the parent object can have up
to five child objects, as specified in the maxOccurs value.DataObject parent = ...
parent.setString("child[3]/grandchild/name", "Bob");
In
this case, the resulting array would be of size three, but the values
for child[1] and child[2] list index
items are undefined. You may want the items to either be a null value
or have an associated data value. In the scenario above, an exception
will be thrown because the values for the first two array index items
are undefined.DataObject parent = ...
// child[1] = null
// child[2] = existing Child
// This code will work because child[1] is null and will be created.
parent.setString("child[1]/grandchild/name", "Bob");
// This code will work because child[2] exists and will be used.
parent.setString("child[2]/grandchild/name", "Dan");
// This code will work because the child list is of size 2, and adding
// one more list item will increase the list size.
parent.setString("child[3]/grandchild/name", "Sam");
// This code will throw an exception because the list is of size 3
// and you have not created an item to increase the size to 4.
parent.setString("child[5]/grandchild/name", "Billy");