• NOTATION Attributes
  • NMTOKEN and NMTOKENS Attributes




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

    NMTOKEN and NMTOKENS Attributes
    Again, a similar relationship exists between NMTOKEN and NMTOKENS attribute types. 
    These types are essentially strings except that they do not allow the existence of white-
    space characters. This can be useful in instances when you want to ensure that a user 
    inputs correct values, such as a license plate number, social security number, or credit 
    card number. They ensure that you don’t get erroneous values due to spaces between 
    characters.
    The NMTOKEN attribute type allows the existence of a single NMTOKEN value. Let’s 
    take the example of an element of type 
    car 
    that has an NMTOKEN attribute called 
    license
    . Here’s a plausible attribute declaration:
    NMTOKEN
    default
    >
    A valid element under this declaration could be:

    more car info

    By using the NMTOKEN attribute type, we’ve ensured that:

    more car info

    will not be allowed in our XML document.
    As you’ve probably guessed, the NMTOKENS attribute type allows one or more 
    NMTOKEN values. Each value in this case is separated by white space.
    NOTATION Attributes


    - 82 -
    Notation attribute types essentially specify a list of predeclared notations, which are 
    defined earlier in the Document Type Declaration. In doing so, the value of the attribute is 
    constrained to one of these notation values. It is a little like the enumerated attribute type 
    with two exceptions. First, you are declaring the values as notations instead of text. 
    Second, the default value is implicitly defined; therefore, it is not followed by our 
    mysterious 
    default
    statement. Notations are discussed later in this chapter, but let’s look 
    at an example of how they are used in the context of declarations of notation attribute 
    types.
    For this notation declaration:
    "http://mysite.com/my_format_processor.exe">
    this NOTATION attribute declaration could be used:
    and this element would be considered valid:

    If you have several notations declared beforehand, you can specify a list of choices in 
    your attribute declaration. For example, in 
    my_code elements have the format attribute values of either my_format or 
    some_other_format. That is, both

    and

    are considered valid under this declaration.
    Table 3.7 summarizes these attribute type declarations.

    Download 2,96 Mb.
    1   ...   76   77   78   79   80   81   82   83   ...   131




    Download 2,96 Mb.
    Pdf ko'rish