DTD - Egenskaper

i DTD används egenskaper för att deklareras genom ATTLIST

förklara egenskap

egenskapsförklaringar används med följande syntax:

<!ATTLIST elementnamn attributnamn attributtyp standardvärde>

DTD-exempel:

<!ATTLIST payment type CDATA "check">

XML-exempel:

<payment type="check" />

nedan äregenskapstypalternativ:

typ beskrivning
CDATA värdet är tecken data (character data)
(en1|en2|..) denna värde är en av värden i en uppsättning
ID värdet är en unik id
IDREF värdet är id för en annan element
IDREFS värdet är en lista över andra id
NMTOKEN värdet är ett giltigt XML-namn
NMTOKENS The value is a list of valid XML names
ENTITY Value is an entity
ENTITIES Value is a list of entities
NOTATION This value is the name of the symbol
xml: Value is a predefined XML value

Default value parameters can use the following values:

Value Explanation
Value Default value of the attribute
#REQUIRED Attribute value is required
#IMPLIED Attribute is not required
#FIXED value Attribute value is fixed

Specify a default attribute value

DTD:

<!ELEMENT square EMPTY>
<!ATTLIST square width CDATA "0">

Valid XML:

<square width="100" />

In the above example, "square" is defined as an empty element with the CDATA type attribute "width". If the width is not set, the default value is 0.

#IMPLIED

Syntax

<!ATTLIST element_name attribute_name attribute_type #IMPLIED>

Example

DTD:

<!ATTLIST contact fax CDATA #IMPLIED>

Valid XML:

<contact fax="555-667788" />

Valid XML:

<contact />

If you do not want to force the author to include the attribute and you do not have a default value option, please use the keyword #IMPLIED.

#REQUIRED

Syntax

<!ATTLIST element_name attribute_name attribute_type #REQUIRED>

Example

DTD:

<!ATTLIST person number CDATA #REQUIRED>

Valid XML:

<person number="5677" />

Invalid XML:

<person />

If you do not have a default value option but still want to force the author to submit the attribute, please use the keyword #REQUIRED.

#FIXED

Syntax

<!ATTLIST element_name attribute_name attribute_type #FIXED "value">

Example

DTD:

<!ATTLIST sender company CDATA #FIXED "Microsoft">

Valid XML:

<sender company="Microsoft" />

Invalid XML:

<sender company="W3School" />

If you want the attribute to have a fixed value and not allow the author to change it, please use the #FIXED keyword. If the author uses a different value, the XML parser will return an error.

List attribute values

Syntax:

<!ATTLIST element_name attribute_name (en1|en2|..) default_value>

DTD-exempel:

<!ATTLIST payment type (check|cash) "cash">

XML-exempel:

<payment type="check" />

eller

<payment type="cash" />

Om du vill att egenskapsvärdet ska vara en av en uppsättning fastställda giltiga värden, använd lista över egenskapsvärden.