• Scenario: Specifying a Subelement That Occurs Once or Not at All
  • Scenario: Specifying a List of Subelements: Only One Occurrence




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

    Scenario: Specifying a List of Subelements: Only One Occurrence 
    Allowed
    To specify a case where only a single selection is allowed (for example, answers to a 
    multiple choice question) your element type declaration would look like this:
    The parser would interpret this declaration as: Elements of type answer can contain 
    either one element of type choice1, or one element of type choice2, or one element of 
    type choice3.


    - 73 -
    For this declaration, a legitimate XML representation would be:



    Other legal answers would be only choice2 or choice3. Thus,

    ...
    ...

    would be unacceptable as the declaration specifies 
    only 
    one occurrence of the elements 
    specified can occur. Similarly,



    is not allowed because choice4 has not been specified in the list of acceptable choices.
    Scenario: Specifying a Subelement That Occurs Once or Not at All
    Suppose you create an online form that requires information from a user, some of which 
    is optional. For example, say you’re asking for personal information and that title is not a 
    required field, while the user’s name and e-mail address is required. You only want one 
    occurrence of each field and you want it in a particular order. Here’s how to specify it:
    According to this, the parser thinks an element of type user consists of one element of 
    type name, one element of type e-mail, and optionally one element of type title.
    Here’s what a valid user element looks like:

    Austin Sours
    austins@being_silly.com
    International Man of Tartness

    An equally valid user could look like this:

    Austin Sours
    austins@being_silly.com

    A nonvalid user element would be:

    Austin Sours


    - 74 -
    international man of tartness

    This example is not valid because the necessary e-mail_address element is missing.

    Download 2,96 Mb.
    1   ...   70   71   72   73   74   75   76   77   ...   131




    Download 2,96 Mb.
    Pdf ko'rish

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Scenario: Specifying a List of Subelements: Only One Occurrence

    Download 2,96 Mb.
    Pdf ko'rish