• String Attributes
  • Table 3.6 Attribute Type Declarations Part 1: Associating an Element with an




    Download 2,96 Mb.
    Pdf ko'rish
    bet77/131
    Sana14.05.2024
    Hajmi2,96 Mb.
    #232039
    1   ...   73   74   75   76   77   78   79   80   ...   131
    Bog'liq
    Ceponkus, Hoodbhoy - Applied XML - Toolkit for Programmers

    Table 3.6 Attribute Type Declarations Part 1: Associating an Element with an 
    Attribute
     
    Partial Attribute Type Declaration
    Interpretation
     
    type default
    >
    An element of type 
    car
    has an attribute 
    called 
    manufacturer
    associated with it.
    type default
    model 
    type 
    default
    >
    An element of type 
    car
    has two attributes, 
    one called 
    manufacturer
    and one called 
    model
    ,
    associated with it.
     
    After we’ve associated the element and the attribute, we need to declare the attribute’s 
    type or class. The list of attribute types is fairly long—ten in total—but many are very 
    similar. Here’s the complete list of allowable attribute types:
    1.
    Strings (text values)
    2.
    Enumerated (one of specified values)
    3.
    ENTITY
    4.
    ENTITIES
    5.
    ID
    6.
    IDREF
    7.
    IDREFS
    8.
    NMTOLKEN


    - 79 -
    9.
    NMTOLKENS
    10.
    NOTATION
    Let’s take a look at each type (or groups of types since several are similar) in greater 
    detail.
    String Attributes
    Strings in attribute types are like strings in all programming languages—they are a series 
    of character data. In XML, string lengths not defined and can be arbitrarily long. From a 
    design perspective, however, we do not recommend using long strings in your attributes.
    To assign a string type to an attribute called authors to an element of type book, here’s 
    what you’d do:
    CDATA
    default
    >
    The CDATA keyword implies a string. Strings can contain all text characters except for 
    special characters like quotation marks and ampersands. These exceptions are noted in 
    Table 3.3
    . You can include these characters by using the entity references specified in 
    Table 3.3
    .
    Here’s what a book element, as specified above, could look like (assume the element 
    type declaration has already been made to allow PCDATA):
    The Hobbit

    Download 2,96 Mb.
    1   ...   73   74   75   76   77   78   79   80   ...   131




    Download 2,96 Mb.
    Pdf ko'rish

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Table 3.6 Attribute Type Declarations Part 1: Associating an Element with an

    Download 2,96 Mb.
    Pdf ko'rish