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] 목록 색인 항목의 값은 정의되지 않습니다. 항목은 널값이 되거나 연관된 데이터 값을 가질 수도 있습니다. 위 시나리오에서는 처음 두 개의 배열 색인 항목 값이 정의되지 않아서 예외가 처리됩니다.
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");