The Schema file looks very similar to other XML files. it is composed of a group of elements, and its root element is "Schema ". The Schema element is the first element in XMLSchema to indicate that the XML document is a Schema document. The End mark of Schema is usually at the end of the document. In this way, the structure of a Schema is as follows: 1.
Schema file structure
The Schema file looks very similar to other XML files. it consists of a group of elements whose root element is"
Schema". The "Schema" element is the first element in XML Schema to indicate that the XML document is a Schema document. The End mark of "Schema" is generally at the end of the document. In this way, the structure of a Schema is as follows:
Schema has two attributes: name specifies the Schema name, while xmlns specifies the namespace contained in the Schema. Note: an XML Schema document can contain multiple namespaces. for example, the following statement specifies three namespaces:
The first is xmlns = "urn: schemas-microsoft-com: xml-data", which specifies that this document is an XML Schema document; the second is xmlns: dt = "urn: schemas-microsoft-com: PES ypes ", which defines the data types that can be used in this document; the third is xmlns: myNS =" http://www.xml _ step_by_step.edu \ ns. xml ", which indicates that elements or attributes defined in myNS may be used below.
2.Define elements and content using Schema
Before describing the definition methods corresponding to the Schema and ETD definitions, let's take a look at the three Schema elements involved: ElementType, element, and group.
1.ElementType element
Used in the Schema documentElementTypeTo declare the elements that will appear in the XML file. the syntax expression of ElementType is as follows:
Among the attributes of ElementType,NameIs the name of the declared element, which is indispensable.ContentIs an important attribute of ElementType. it specifies whether the elements declared by ElementType are null, contain text, contain child elements, or contain both text and child elements.Dt: typeSpecifies the data type of the element.OrderSpecifies the ordering rules for the child elements of the element. Finally,ModelSpecifies whether the element can contain elements and attributes not defined in the Schema. it is mainly used for the introduction of other schemas, that is, the introduction of other "namespaces. The concept of "namespace" may be unfamiliar to everyone. now you only need to understand that several different DTD or Schema definitions can be used in an XML file at the same time.
The following table lists the possible values of the model:
Value |
Description |
Open |
It indicates that this element can contain other elements and attributes not defined in the XML Schema. |
Closed |
It indicates that this element can only contain elements and attributes defined in the XML Schema. |
By default, the model value of XML Schema is "open". that is, this element can contain other elements and attributes not defined in XML Schema. However, this does not mean that any element or attribute can appear in the Schema. The premise is that these "heterogeneous" elements and attributes must be defined in a separate XML Schema, in addition, the source must be specified in the namespace form of the referenced elements.
2.Element
ElementType is only used to declare elements. what is the content of an element depends on its child element.Element. Element syntax:
Element is actually a reference to the ElementType declaration in the Schema.TypeAttribute specified. The type attribute is indispensable. to ensure that the type is a declared element, the value must be exactly the same as the name attribute in a ElementType. The other two attributes are dispensable.MinOccursSpecify the minimum number of times the element appears in its parent element. the default value is 1, indicating that the element appears at least once. you can also set the value to 0, indicating that the element is optional and does not appear.MaxOccursThe maximum number of times the element appears. the default value is also 1, indicating that the element appears at most once. The value can also be "*". this indicates that the number of times this element appears in the XML instance document is not limited.
3.Group element
DTD has the concept of grouping. correspondingly, the Schema also has the"Group"Element. Its syntax is similar to the element:
AttributeType is also an important element in Schema. it is used to define the attribute types that appear in this Schema document. The AttributeType syntax is as follows:
Name = "property name" dt: type = "property type" dt: values = "enumeration value list" default = "default value" required = "{yes | no}">
Name
Name is self-evident. it is naturally the name of the declared attribute type. Note that this attribute is required.
Dt: type
Dt: type specifies the data type of the declared attribute. it not only supports all the top 10 data types contained in the DTD, but also supports some extended attributes. The following table lists the relationships between the ten basic attributes in the Schema and the attributes in the DTD:
Basic Schema type |
Data type in DTD |
String |
# PCDATA |
Enumeration |
ENUMERATED |
Id |
ID |
Idref |
IDREF |
Idrefs |
IDREFS |
Nmtoken |
NMTOKEN |
Nmtokens |
NMTOKENS |
Entity |
ENTITY |
Entities |
EMTITIES |
Notation |
NOTATION |
3. dt: value
Dt: value is valid only when dt: type is set to "enumeration". In this case, dt: value must list all possible values.
4. default
Default specifies the default value of this attribute type. The default value must be valid. for example, when dt: type is set to "enumeration", the default value must come from the value listed by dt: value.
5. required
Required specifies whether this attribute is required for elements that reference it. The value yes indicates that it is required, and the value no indicates that it is not required.
6. attribute element
The relationship between AttributeType and attribute is the same as that between ElementType and element. AttributeType only declares attributes and specifies which attributes of an element must depend on attribute.
The above is a detailed description of the instance code used to verify the XML concept of Schema. For more information, see other related articles in the first PHP community!