tailieunhanh - Pro PHP XML and Web Services phần 2

chẳng hạn như trong bảng liệt kê 3-26, là một hình thức của nhóm. Đây là một nhóm địa phương giấu tên. Nhóm cũng có thể là sự lựa chọn hoặc tất cả. Trình tự A, như bạn đã biết, có nghĩa là các yếu tố phải xuất hiện trong đó trình tự chính xác. Một sự lựa chọn có nghĩa là một số lượng nhất định được xác định bởi thuộc tính maxOccurs | 78 CHAPTER 3 VALIDATION same thing. For instance the element rue is the same as the element street. Based on these declarations the following two documents are both valid address name street address adresse nom rue adresse Element Groups The sequence element you have seen used earlier in the chapter such as within Listing 3-26 is a form of grouping. It is an unnamed local group. Groups may also be choice or all. A sequence as you already know means the elements must appear in that exact sequence. A choice means that a certain number determined by the maxOccurs and minOccurs attributes which both default to 1 may be selected. Using all allows the elements to appear in any order although all the elements must be present within the content of a parent element. When you create named groups you can share them so you don t need to define local groups. You can just reference the named group. Take the case of an address. A document may have a shipping address as well as a billing address. In most cases the elements required are the same. You could create a named group and share between the two as follows xsd group name Address xsd sequence xsd element name street xsd element name city xsd element name state xsd element name zipcode xsd sequence xsd group xsd element name BillingAddress xsd sequence xsd group ref Address xsd sequence xsd element xsd element name ShippingAddress xsd sequence xsd element name attention type xsd string xsd group ref Address xsd sequence xsd element CHAPTER 3 VALIDATION 79 The xsd group element is laid out similarly to the xsd element elements. Notice within the xsd sequence elements for the element declarations that the xsd group element does not include a name attribute but rather a ref attribute. This attribute instructs the XML Schema to reference the group named Address. The ShippingAddress declaration also shows how you can use a group as well as declare additional elements. Attributes I ve shown only simple attribute declarations up .