XML constraints, xml
XML constraints-you can understand the constraints and write xml files that comply with the rules according to the constraints. DTD Constraints
1) Import dtd
Internal Import
|
<! DOCTYPE note [
<! ELEMENT note (to, from, heading, body)>
<! ELEMENT to (# PCDATA)>
<! ELEMENT from (# PCDATA)>
<! ELEMENT heading (# PCDATA)>
<! ELEMENT body (# PCDATA)>
]> |
External Import
Local file system:
|
<! DOCTYPE noteSYSTEM"Note. dtd"> |
Public external import:
|
<! DOCTYPE root elementPUBLICHttp://gz.itcast.cn/itcast.dtd> |
2) DTD syntax
Constraint label
<! ELEMENT name Category> or <! ELEMENT name (ELEMENT content)>
Category:
EMPTY Tag: EMPTY. The element must be an empty element.
Common string: (# PCDATA ). It indicates that the content of an element must be a normal string (it cannot contain sub-tags ).
ANY content: ANY. Indicates that the content of an element can be any content (including sub-tags)
(Element content ):
Sequence problems:
<! ELEMENT name (child ELEMENT name 1, child ELEMENT name 2,...)>: displays child tags in sequence
Number of times:
Tag: it must appear only once.
Tag +: at least once
Tag *: 0 or n times.
Tag? : 0 or 1 time.
Constraint attributes
<! ATTLIST element name attribute type default value>
Default Value:
# The REQUIRED attribute value is REQUIRED.
# IMPLIED attributes are not required
# The FIXED value attribute is not mandatory, but the attribute value is FIXED.
Property type:
CDATA: A common string.
(En1 | en2 |...): indicates that you must select one of the values.
ID: indicates that the attribute value must be unique in an xml document. The value cannot start with a number.
Schema Constraints
Namespace: Tell the xml documentWhich element isSchemaDocument Constraints. In an xml document, different labels can be restricted by different schema documents.
1) when a namespace is restricted by the schema document
2) When multiple namespaces are restricted by multiple schema documents
3) default namespace
4) No namespace