XML constraints, xml

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.