XML Schema Learning Notes (2)
Zhang Xiaoot
1. About Include
The include element can introduce an external definition and declaration into the document and as part of the new Schema document, but must be aware of that the target namespace containing the member must be the same as the included target namespace. Specific writing examples are:
2. If a type is extended from another type, it is defined as a parent type ELEMENT. In the instance document, it can be replaced by a subtype's Element instance, but the specific specificity must be specified by XSI: Type. Types of. E.g:
xsd: sequence>
xsd: complexType>
xsd: restriction>
xsd: element>
xsd: sequence>
xsd: extension>
complexContent>
xsd: complexType>
In the XML instance documentation, you can be such (and object-oriented, similar concepts):
human>
3. About the replacement group
XML Schema provides a mechanism called replacement group that allows the originally defined element to be replaced by other elements. More specifically, this set group contains a series of elements, each element in this replacement group is defined as a specified element, and this designated element is called head element, it is necessary to pay attention. The head element must be declared as a global element. Note that when an instance document contains the type of elements, it is derived from their head elements when the type of elements is replaced. At this time, it is not necessary to use the XSI: Type mentioned earlier to identify these Derived types, when defining the replacement group, does not mean that the head element cannot be used, and only the elements in this replacement group can only provide a mechanism that allows the elements to be replaced. E.g:
Substituiongroup = "comment" /> xsd: complexType> xsd: element> xsd: schema> Below is an example of an instance document: 2004-08-15 shipdate> order> 4, abstract elements and abstract types When an element or type is declared as "Abstract", then it cannot be used in the instance document. When an element is declared as "Abstract", the member of the element's replacement group must appear in the instance document. When an element is defined as "Abstract", all instances of all associated elements must use "XSI: Type" to indicate a type, this type must be non-abstract, at the same time is the abstract type declared in the definition Detective type. First, change the statement of the above Comment element to: Then, only CustomerComment and ShipComment are valid in the above Order instance. Second, if there is a definition of the following: Targetnamespace = "http://cars.example.com/schema" XMLns: target = "http://cars.example.com/schema"> complexContent> complextype> complexContent> complextype> schema> According to the above definitions and declarations, the following instance pieces cannot be verified: The following can be verified by modified. XMLns: xsi = "http://www.w3.org/2001/xmlschema-instance" xsi: type = "car" /> 5. In order to prevent types from being derived (including derived by limiting derived and by extending derived), you can use Final to set (similar to the concept of Final in Java), which is three: restriction, extension, # all. There is an optional FinalDefault property in the root element schema element of the mode file, which can be taken to one of the values allowed by the final property. The effect of specifying the value of the FinalDefault property is equal to specifying the final property in each type definition and element declaration in the mode document, and its value is the value of the FinalDefault property. If you want to block the previous Person, we need to modify the definition as follows: xsd: sequence> xsd: complexType> 6, because the elements associated with the parent type in the instance document (that is, the elements of the parent type) can be replaced by derived subtypes, which already has a detailed description and examples in 2. At the same time, XML Schema also provides a mechanism to control derived types, and mechanisms used in instance documents. This mechanism is controlled by the type of block attribute, which can be valued: restriction, extension, # all. Like the final properties, there is an optional property BlockDefault in the root element schema element of the mode document, which is one of the values allowed by the BLOCK attribute. Specifies the role of the blockDefault property to specify the Block property for each type definition and element declaration in the mode document. For example, in the previous example we want to block the use of Father to replace Person, we need to modify the definition of Person as follows: xsd: complexType> The Block property that is "extension" will prevent the use of Person in an instance document (you can block the father to replace the Person), but it does not block the Person by constraints. 7. Another control mechanism for derived types is derived from simple types. When defining a simple type, we can use the Fixed property to modify all of its defined parameters to prevent these parameters from being modified in the type derivation, for example: Fixed = "true" /> xsd: restriction> xsd: SimpleType> When this simple type is defined, we can derive a new zip coding type, where we use a parameter that is not fixed in the basic type: xsd: restriction> xsd: SimpleType> However, we cannot purchase a new type of zip code type: where we redefined any parameters that have been fixed (fixed) in the base type: xsd: restriction> xsd: SimpleType>