setWithCreate 機能を使用して、ネストされたビジネス・オブジェクトの複数インスタンスを作成します。
<?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>maxOccurs の値で指定するように、親オブジェクトは最大 5 つの子オブジェクトを持つことができることに注意してください。
DataObject parent = ... parent.setString("child[3]/grandchild/name", "Bob");この事例では、結果の配列のサイズは 3 ですが、child[1] および child[2] のリスト指標項目の値は未定義です。項目は、ヌル値にするか、または関連したデータ値を持たせることが必要な場合があります。上記のシナリオでは、最初の 2 つの配列指標項目が未定義であるため、例外が throw されます。
DataObject parent = ... // child[1] = ヌル // child[2] = 既存の子 // child[1] はヌルであり、作成されることから、このコードは機能します。 parent.setString("child[1]/grandchild/name", "Bob"); // child[2] が存在して使用されるため、このコードは機能します。 parent.setString("child[2]/grandchild/name", "Dan"); // 子のリストのサイズは 2 であり、 // リスト項目を 1 つ追加するとリストのサイズが増加するため、 // このコードは機能します。 parent.setString("child[3]/grandchild/name", "Sam");
// リストはサイズが 3 であり、サイズを 4 に増加させる項目を // 作成していなかったため、このコードは例外を throw します。 parent.setString("child[5]/grandchild/name", "Billy");