Third, XML Schema data type
XML Schema provides a rich set of built-in data types for defining the types of allowed elements. Here will be introduced some universal types that fully comply with the C # standard.
1, basic data type
The basic data type is the most basic constituent block for each data type used in XML Schema. Customized types can be constructed based on these types. These types include:
Boolean can be 1 (True) or 0 (False).
DateTime represents partial optional, format: ccyy-mm-ddthh: mm: ss
For example: 2005-3-18T14: 48: 12
Decimal represents a decimal number of any precision.
String character data.
INT represents an integer between -2, 147, 483, 648 to 2, 147, 483, 648.
NonnegativeInteger represents an integer greater than or equal to 0.
NonpositiveInteger represents an integer that is less than or equal to 0.
SHORT represents an integer from -32768 to 32767.
E.g:
xsd: sequence>
xsd: complexType>
xsd: element>
xsd: sequence>
xsd: complexType>
xsd: element>
xsd: schema>
The above document corresponds to an effective XML document as follows:
XML Version = "1.0"?>
name>
ContactDetails>
2, simple type
Although many functions are obtained from the built-in data type, in many cases, only the data type limits the value of the data is not enough. Here you will see about constraints before learning the simple type. Constraint
ENUMERATION Separate a set of specified values. It constrains the data type as the specified value.
FractionDigit specifies the maximum number of digits after the decimal point.
Length length unit.
MINEXCLUSIVE Limits, all values must be greater than this value.
MaxExClusive upper limit, all values should be less than this value.
Minlegth length unit minimum.
The maximum number of MaxLength Length Units.
MininClusive minimum, all values should be greater than or equal to this value.
The maxinclusive maximum, all values should be less than or equal to this value.
The value of the Pattern data type must match the specified mode, and the pattern value must be a regular expression.
TotalDigits specifies the value of the maximum number of digits.
Whitespace is: Preserve (spaces in the value cannot be changed), Replace (all tabulation
The compliments, newline characters and carriage return are replaced by spaces), collapse (executing Replace, deleting
Depending on adjacent, ends at the beginning and at the beginning).
To apply the above constraints, it is necessary to use the element restriction. There are 2 properties in this element: ID attribute is the unique identifier of the RESTRICTION element in the mode document, and the base property is set to a built-in XSD data type or an existing simple type definition, he is a limited type.
E.g:
xsd: restriction>
As above, the smallest length of the string is limited to 4 characters, and the maximum length is limited to 10 characters.
xsd: restriction>
As above, an integer range is set between 1 and 100.
xsd: restriction>
As above, the string can only be three values that enumerate.
Simple type
The simple type is a custom data type for possible values of a node. Creating a simple type requires using the SimpleType element, which is defined as follows:
The ID attribute should uniquely indicate the SimpleType element in the document, and Name cannot use a colon character. SIMPLETYPE cannot contain elements, nor can you have properties, depending on the rules defined in SimpleType, it is basically a value, or a collection of values. E.g:
xsd: restriction>
xsd: SimpleType>
The above document corresponds to an effective XML document as follows:
The following is an invalid XML document:
Again for example:
xsd: restriction>
xsd: SimpleType>
The type of PersonStitle, which is defined above is a string type, but its value can only be Mr., MRS. Or MISS. One.
Complex type
Complex type definitions must use the ComplexType element where you can contain properties and elements. In complex types of use, mainly COMPLEXTYPE and SIMPLEPE are used in conjunction. The format is as follows:
E.g:
Default = "john" /> Maxoccurs = "unbounded" nillable = "true" /> xsd: sequence> xsd: complexType> xsd: restriction> xsd: SimpleType> xsd: restriction> xsd: SimpleType> A complex type is achieved, which implements a complex type FullName, which contains two simple typesonsfirstname and PersonStitle. Packets and attributes In some more complex definitions created for defining an XML document, there will be some elements set, the property set, which is our concept of grouping. The Group definition is used in the group element. E.g: xsd: choice> xsd: group> xsd: element> Packets for attributes should use attributegroup elements, such as: xsd: attributegroup> xsd: complexType> xsd: element> The above document corresponds to an effective XML document as follows: Content model The content model can limit the elements, properties, and types used in the XML document to determine which levels can add their own elements and properties on which levels of the XML instance. Any When the element is declared in XML, Any is the default content model, which can contain text, elements, and spaces. This model can be used if the content of the elements is allowed, and this model can be used without the modification of the mode file. E.g: xsd: sequence> xsd: complexType> xsd: element> Maxoccurs = "unbounded" /> xsd: sequence> xsd: complexType> xsd: schema> The XSD: Any element in the example shows that this type allows you to add content. The value allowed by the Namespace property is: ## Any (element can come from any namespace) ## taher (element can come from namespace outside the target namespace in addition to the parent element of this element) ## local (element is not limited by namespace) ## TargetNameSpace (Element is from the parent element's target namespace) ProcessContents Attribute Description The operation performed when the element created here is verified, and the value is as follows: Strict (indicating that the XML processor must get the mode associated with those namespaces and verify elements and properties) LAX (Similar to Strict, just if the processor can't find the mode document, no error) SKIP (Distribution Mode Document Verification XML Document) An effective example of the above mode is as follows: XML Version = "1.0"?> middle> name> EMPTY The EMPTY element prohibits the sub-elements of the element or element as a declared element, and if it is necessary to ensure that the element does not include sub-elements, the text or even spaces, you can use it. Using the XSD: AnyType type when XSD is used, this means that the element can only contain attributes, for example: xsd: restriction> xsd: complexContent> xsd: complexType> xsd: element> xsd: schema> The above is a complex type, only allows an AGE attribute. In the example, the ComplexContent element can represent the content of ComplexType to expand or limit, where we limit its content, so use the restriction element, if an Exension element is used if an enlargement is used. Element (I have learned the front) Mixed The last content model is Mixed, which contains text, content, and properties. Setting the value of the Mixed property to true on the ComplexType element, a declared a MIXED content model. E.g: xsd: sequence> xsd: element> xsd: schema> An effective example of the above mode is as follows: XML Version = "1.0"?> In the example, the Contact element contains text and element first. (Finish)