什么是XML中的属性

在本文中,我们将学习如何使用XML属性

使用AttList声明声明XML中的属性。

例如 :

<!ATTLIST element-name attribute-name attribute-type default-value>

                       example:

                      <!ATTLIST  payment  CDATA "check">

                      XML example:

                      <payment ="check" 

注意:属性可以有几种类型

Attribute Type
                     Attributes Description

                    CDDATA
                     The value is character data

                    ID
                     The value is unique id

                    IDRef
                     The value in the id of other element

                    IDREFS
                     The value in the id  of list of other ids

                    NMTOKEN
                     The value is a valid xml name

                    XML:
                     The value is the predefine or default  xml value

                    Entities
                     The values is the list of entitles

默认值也可以。
这些都在遵循

Value
                    description

                    value
                     default value of the attributes

                    #REQUIRED
                     The value must be required

                    #IMPLIED
                     The Attribute is not required

                    #FIXED value
                     Attribute value fixed

默认属性值

DTD:

                      <!ELEMENT square EMPTY>

                      <!ATTLIST height width CDATA "0">

                      Valid XML:

                      <square height="200" 

#REQUIRED

<!ATTLIST element-name attribute-name attribute-type #REQUIRED>

注意:这是#required的声明

例子:

DTD:

                      <!ATTLIST personal  number CDATA #REQUIRED>

                      Valid XML:

                      <personal  number="677" 

                      Invalid XML:

                      <personal

#IMPLIED

<!ATTLIST element-name attribute-name attribute-type #IMPLIED>

注意:这只是#implied的声明部分

例子:

DTD:

                      <!ATTLIST  fax no CDATA #IMPLIED>

                      Valid XML:

                      <fax no="555-9995588" 

                      Valid XML:

                      <fax 

#FIXED

<!ATTLIST element-name attribute-name attribute-type #FIXED "value">

注意:这只是#fixed值的声明部分

例子 :

DTD:

                      <!ATTLIST company CDATA #FIXED "MCN  Private solution">

                      Valid XML:

                      < company="MCN  private solution" 

                      Invalid XML:

                      < company="dotnet factor" 

枚举属性值

如何声明它

<!ATTLIST element-name attribute-name (en1|en2|..) default-value>

例子 :

DTD:

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

                      XML example:

                      <pay type="check" 

                      or

                      <pay type="cash" 

枚举属性值必须是有效值之一(这里必须是check或者cash之一)。

日期:2020-04-11 22:50:10 来源:oir作者:oir