XML Schema modeling to help you (2) Author: Xiao Chai Road www.ASPCool.com
Composite type definitions, elements, and attributes declarations in XML Schema, for those who have their own content, and composite types that can carry their own properties, with simple types that cannot have element content and attributes, their representations have essentials different. In the instance document, there is a significant difference between the declarations that can create new types (regardless of simple and complex) definitions and allow elements and attributes (whether simple or complex) declarations (whether or not, complex). In this section, the composite type will be defined, and how to declare the elements of the composite type and its properties are described in more detail. In a mode document, when you need to define a new composite type, you should use the ComplexType element to be defined, such typical definitions include element declarations, elements reference, and attribute declarations. These elements declare that they are their own type, as well as the correlation between the element name controlled by the related mode and the type of constraint that controls these elements in the form of the example document. The element is declared by using the ELEMENT element, the attribute is declared by using the Attribute element. For example, USADDRESS is defined as a composite type, so it sees that it contains five elements declarations and a statement that it contains five elements (see Code 3).
A declaration that references global elements, which allows the referenced elements to be referenced in the instance documentation in elements associated with the declaration. So, for example, the Comment element in PO.XML can also appear in Shipto, BillTo, and Items elements, because the declaration of composite type definitions that reference Comment also appear in the declarations of these three elements. A statement of a global element also allows elements to appear in a top document element in an instance document, so the PurchaseOrder element is declared as a global element as a global element in PO.XML. The top elements in PO.xml appear. It is worth noting that the Comment element based on this basic principle is also allowed in the document such as PO.xml as a top element. There are many restrictions on the use of global elements and attributes, one of which is a global statement that cannot contain references. The global statement definition cannot contain REF properties, they must use the Type property (or followed by an anonymous type definition). The second restriction is that constraints cannot be placed in a global statement, although they can be placed in a local statement that references global statements. In other words, the global statement cannot contain MinoCCurs, MaxocCurs, or USE properties. With regard to the use of constraints, it will be given in the next section. As a result of the number of times, we see that the value of the Minoccurs property is 0 in the element declaration in code 5, so the Comment element is an option in the PurchaseOrDertype type. In general, when the value of the MinoCCURS of an element is 1 or more, the element must appear. The maximum number of elements can appear is determined by the maxoccurs attribute in the statement. This value may be a positive integer such as 1, or a large integer 100, or in the form of "unbounded" to indicate that the number of unlimited appearances. The default value for the Minoccurs and Maxocus properties is 1. Therefore, when an element is as Comment, it does not define the maxoccurs property, then this element cannot be more than once. If only the Minoccurs property value is specified, it must be less than equivalent to the default value of MaxocCurs, that is, if Minoccurs appears separately, the value can only be 0 or 1, because the effective value of MinoCurs must be less than equivalent to Maxoccurs value. Similarly, if only the maxoccurs property is specified, it must be greater than or equal to the default value of Minoccurs, that is, the value must be 1 or more. If both attributes are omitted, the elements must appear and only once. For attributes, it can have two options: once or not, there is no other number of occurrences. Therefore, the syntax of the specified attributes has different symnages of the elements. It is important to note that the attribute statement can use a USE property to indicate whether the attribute needs to appear (see the declaration of the partnum attribute in PO.xsd). The default values of attributes and elements are declared using the default property, but this property has different semantics in different situations. When an attribute is declared using the default value, if the attribute appears in the instance document, the value of the attribute is the value that the attribute appears in the instance document, that is, the value in the instance document is the final valid value. If the property does not appear in the instance document, the mode processor will consider the value of this attribute equal to the value of the default property in the declaration. It should be noted that the attribute default value is only meaningful when the attribute itself is "optional". If in the statement, the default value is specified, but also sets the USE attribute to other values other than "optional" (that is, the appearance), the processor will generate errors. That is, the default value of the attribute is only effective when the property does not appear in the instance document.