XML Schema Learning (1)

xiaoxiao2021-03-06  18

Recently, I've used a standard document for the interface 1 for WMFC definitions. The definition of XML format uses XML Schema. Since XML Schema has a lot of roles in many ways, there is a trend of replacing DTD, so I wrote some Studying notes, there is a hurting place, please refer to you!

Other aspects of XML Schema are not here, directly enter the theme, and the basic syntax of XML Schema.

XSDL (XML Schema Definition Language) consists of other nodes of elements, attributes, namespaces, and XML documents.

First, the elements in XSD

The XSD documentation is at least: the definition of the Schema root element and XML mode namespace, element definition.

1, Schema root elements

The syntax is as follows:

...

You must define one in XSD and can only define an SCHEMA root element. Root elements include mode constraints, definitions, definitions, version information, language information, and other properties of the XML mode namespace.

2, element

The syntax is as follows:

The elements in the XSD are declared using the Element identifier. Where the Name property is the name of the element, the Type property is the type of element value, where it can be a built-in data type or other type of XML Schema.

example:

The effective XML document corresponding to the above document is as follows:

String

There are two attributes in the definition of the elements: MinoCCURS and Maxoccurs. The Minoccurs defines the least number of times that the element appears in the parent element (default is 1, the value is an integer that is equal to 0), and the maxoccurs defines the maximum number of times that the element appears in the parent element (default is 1, the value is greater than or equal to equal 0 integers). You can set the value to unbounded in maxoccurs, indicating that the maximum number of elements is not limited.

example:

Indicates that the type of element user is String, and the number of times the number of times is 0 (which is optional) is not limited.

3, reference elements and replacement

The syntax is as follows:

The reference is to achieve the Ref property of the ELEMENT tag. Mainly suitable for avoiding the same element multiple times in the document, and should define the elements of the root elements to be used as the child elements of the root element to reference it anywhere in the document.

Here you can also set an alias for a certain element (even understanding ^ o ^), the method is as follows:

The effective XML document corresponding to the above document is as follows:

String

or:

string

It is mainly implemented using the attribute substitudeGroup in the Element identifier.

4, set the default and fixed value

The syntax is as follows:

With the setting of the DEFAULT property, you can give the default value when the CITY element is defined in the XML document. Use the fixed property, you can set a fixed value CHINA to the element country and do not allow changes!

5, using the combiner control structure

The SEQUENCE combiner defines a column element to be displayed in the order specified in the mode (if it is optional, or not). The syntax is as follows:

The ALL combiner allows the defined elements to be displayed in any order, and the sub-elements of the ALL element are required by default, and at a time up to once. The syntax is as follows:

The Choice combiner allows you to specify one of the multi-group declarations for mutual exclusion. The syntax is as follows:

Second, define attributes

In the XML Schema document, you can define properties according to the method of defining elements, but is higher than restricted. They can only be simple, only text, and there is no subview. The properties that can be applied in the Attribute element definition are as follows:

DEFAULT initial default

Fixed cannot modify and overwrite properties fixed values

Name attribute name

Ref for references defined by the previous attribute

TYPE This property is the XSD type or simple type

How to use attributes

Form Determines the local value of AttributeFormDefault

The only ID of the properties in the ID mode document

Default, fixed, name, ref and type properties are the same as the corresponding properties defined in the Element tag, but Type can only be a simple type. The value of the USE property can be: Optional (this is not required, this is the default attribute), prohibited, or required (forced).

1, create properties

The syntax is as follows:

This statement defines an attribute called AGE, which must be an integer. When it is added to the mode, it must be the child of Schema elements, ComplexType elements, or attributegroup elements. example:

The above document corresponds to an effective XML document as follows:

string

As shown above, to attach the properties on the element, the properties should be defined or referenced after the combiner in the ComplexType definition.

转载请注明原文地址:https://www.9cbs.com/read-46378.html

New Post(0)