July 23, 2011
important reminder: The system detects that your account may have stolen the risk, please see the risk warning as soon as possible, and immediately change your password. Close
Netease blog security alert: The system detected that your current password is less secure, for your account security, we recommend that you change your password immediately amend the timely closure
XSDL ( XML Schema Definition Language) by the elements, attributes, namespaces, and XML documents to other types of nodes.
one, XSD elements
XSD document must contain at least: schema root element and XML schema definition namespace, element definitions.
1, schema root element syntax is as follows:



must be defined in the XSD to define a schema and only one root element. Including the root element model of restraint, XML schema definition namespace, other namespaces definitions, version information, language information, and other properties.
2, elements
syntax is as follows:

XSD elements are declared using the element identifier. Where name attribute is the name of the element, type attribute is the type of element values, where you can be an XML Schema built-in data types or other types.
example:



above document corresponds to the valid XML documents as follows: < br />

string
the definition of the elements there are two attributes: minOccurs and maxOccurs. Which defines the element minOccurs parent element appear in the least number of times (default is 1, is an integer greater than or equal to 0), maxOccurs defines the elements appear in the parent element maximum number (default is 1, is large in an integer equal to 0). In the maxOccurs can set the value to unbounded, that appeared on the maximum number of elements there is no limit.
example:



expressed as elements of user type is string, the number of occurrences of at least 0 (that is optional), up to a maximum limit.
3, refer to the element and replace
syntax is as follows:










tag reference element is the use of the ref attribute to achieve. Mainly applied to avoid multiple definitions in the document with an element, the element should be defined as the frequent use of the root element children, anywhere in the document to refer to it.
here one can also define the elements of an alias, as follows:





< br />


< / xsd: complexType>


above document corresponds to the valid XML documents as follows:


string
or:


string

main element identifier is to use the property substitutionGroup achieved.
4, set the default value and the fixed value
syntax is as follows:


properties by default settings, you can no city in the XML document element definition given default values. The use of the fixed attribute, you can set to a fixed element value country china, and not allowed to change!
5, the use of combined control structure
sequence combination, define a list of elements must appear in the order specified in the schema (if it is optional, it may not show .) Syntax is as follows:









< br />

all combinations, allowing the element can be defined in accordance with any order, all child elements must be in default, and a maximum display time. Syntax is as follows:











choice combiner, allows you to specify multiple statements in a for mutually exclusive conditions. Syntax is as follows:









< br />

Second, the definition of property
in the XML Schema document element method can be defined in accordance with defined properties, but limited level is higher. They can only be simple types can contain text, and no sub-attributes. The attribute element can be used in the definition of the attributes are as follows:
default initial default value
fixed and can not modify the properties covered by a fixed value
name name of the property
ref attribute of the previous definition of reference
type of the attribute of the XSD type or simple type
use how to use the property
form to determine the local value attributeFormDefault
id schema document properties unique ID Default, fixed, name, ref, and the type attribute in the element marked with the corresponding properties defined in the same but the type can only be a simple type. Use attribute values ??can be: optional (attribute is not required, this is the default property), prohibited or required (attribute is mandatory).
1,
create attribute syntax is as follows:
< br />
This statement defines a property named age, its value must be an integer. Add it to the model, it must be when the schema element, complexType, or attributeGroup element child of the element.
example:









< br />
above document corresponds to a valid XML document as follows:


string

As shown above, we should attribute attached to the elements, attributes should be In the combiner complexType definition after the definition or reference.
three, XML Schema data types
XML Schema provides a rich set of built-in data types, used to define element types allowed. The following describes some of the full compliance with the standard C # generic type.
1, the basic data types
basic data types in XML Schema data types used in the basic composition of each block. These types can be constructed according to the custom type. These types include:
boolean can be either 1 (true) or 0 (false).
dateTime that time, some optional, format: CCYY-MM-DDThh: mm: ss
For example :2005-3-18T14: 48:12
decimal represents arbitrary precision decimal numbers.
string character data.
int expressed from -2,147,483,648 to 2,147,483,648, an integer between.
nonNegativeInteger that is greater than or equal to 0 an integer.
nonPositiveInteger that is less than or equal to 0 an integer.
short from -32768 to 32767 that of an integer.
For example:















< xsd: element name = "first" type = "xsd: string" />








above document corresponds to a valid XML document as follows:



santld

wang

10.27

2, simply type
Although the built-in data types to get a lot of features, but in many cases, only data types to limit the value of the data is not enough. This simple type of learning before you take a look on the constraints.
constraints
enumeration areas separated by a space of a set of specified values. It is the data type constraints for the specified value.
fractionDigit specify the maximum number of digits after the decimal point.
length unit of length.
minExclusive lower limit, all the values ??must be greater than this value.
maxExclusive upper limit, all the values ??should be less than this value.
minLength minimum number of units of length.
maxLength the maximum number of units of length.
minInclusive minimum, all values ??should be greater than or equal to the value.
maxInclusive maximum, all values ??should be less than or equal to this value.
pattern data type of value must match a specified pattern, pattern value must be a regular expression.
totalDigits specify the maximum number of digits of the decimal value.
whiteSpace its value: preserve (the value of the space can not be changed), replace (all the tabs
, newline, spaces and carriage returns are place), collapse (executive replace, delete
In addition to the adjacent, and the beginning of the end of the space).
to apply the above constraints, it is necessary to use elements of restriction. This element has two attributes: id attribute is the restriction element of the schema document unique identifier, base property to a built-in XSD data types or existing simple type definition, he is a restricted type.
For example:
above, the minimum length of the string is limited to four characters, the maximum length is limited to 10 characters.




above, the range of a set of integers between 1 and 100.





above , the string can only enumerate the three values.

simple type is a simple type node may further restrict the value of custom data types. Create a simple need to use the simpleType element type, which is defined as follows:

id attribute should only indicate the simpleType element within the document, name can not use the colon character. simpleType can not contain elements that can not have attributes, according to the rules defined in the simpleType, which is basically a value or a set of values.
For example:







above document corresponds to the effective The XML document is as follows:
Santld
The following is an invalid XML document:
SS or Santld wang
As another example:









personsTitle type defined above is a string type, but its value can only be is Mr., Mrs. or Miss. one of them.

complex type definition must use a complex type complexType element, where you can contain attributes and elements. The use of a complex type, mainly used in conjunction complexType and simpleType. Format is as follows:

For example:



default = “John” />
maxOccurs =” unbounded “nillable =” true “/>
default = “Doe” />










above to achieve a complex type, the example implements a complex type FullName, which contains two simple types PersonsFirstname and PersonsTitle.
groups and attributes as defined in the XML document and create some of the more complex definition, there will be some set of elements, attributes the combination of sets, which we will use the group concept. Grouping is used in the definition group element.
For example:


< xsd: element name = "Beijing" type = "xsd: string" />









group of properties, you should use attributeGroup elements, such as:










above document corresponds to a valid XML document as follows:

content model content model can be used within the XML document elements, attributes and types of constraints, the user can determine what level in the XML instance to add your own elements and attributes.
any element when the XML declaration is the default when any of the content model, which can contain text, elements and spaces if the content allows you to add elements, and no room to modify model file, you can use the model.
For example:




< br />

< br />

< br />



maxOccurs = “unbounded” />



example of xsd: any element of this type allows you to add note the content. namespace property allows the values:
# # any (element from any namespace)
# # other (in addition to the elements can come from the parent element elements located outside the target namespace of the namespace)
# # local (elements are not namespace restrictions)
# # targetNamespace (elements from the parent element target namespace)
processContents property description of the elements created here, when performed to verify the operation of the following three kinds of values:
strict (marked with an XML processor namespace must be associated with those models, and validate elements and attributes)
lax (with strict, except that if the processor can not find the model document, and no error)

skip (do not use the schema document to validate XML documents)
a valid instance of the model are as follows:
< br />

santld

San < / nameInChina>

wang


empty
empty elements or elements against the text declared as empty as a child of the element, if you want to ensure that the element does not include child elements, text and even a space, you can use it in XSD when using xsd: anyType type to limit it, so that means that elements can contain attributes, such as:



< br />


< br />




above is a complex type, only one age attribute in the example can be expressed complexType complexContent element content to be expanded or limit, where we restrict the content, so the use of the restriction element, if extended into the use exension elements.
element (front has to find out about a)
Finally, a mixed content model is mixed, it contains text, content, and properties in the complexType element to set the value of the mixed attribute is true, a statement has a mixed content model, such as:










a valid instance of the model are as follows:

My first name is Santld . contact element in the example contains the text and elements first.