• Scenario: Specifying a Subelement That Occurs Zero or More Times
  • Scenarios: Specifying Subelements That Occur at Least Once and




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

    Scenarios: Specifying Subelements That Occur at Least Once and 
    Possibly More
    Let’s say in our above scenario that typical users have more than one e-mail address 
    and, for some inexplicable reason, want e-mail sent to both addresses. Though we 
    require only one e-mail address element, why restrict them from giving us another one? 
    Here’s how you’d declare a subelement to occur at least once, possibly many times:
    The parser thinks that user elements consist of one name element, at least one e-
    mail_address element—possibly more—and one optional title element.
    Valid user elements look like this:

    Austin Sours
    austins@being_silly.com
    austins@being_even_sillier.commail_address>
    International Man of Tartness

    or this:

    Austin Sours
    austins@being_silly.com
    International Man of Tartness

    or even this:

    Austin Sours
    austins@being_silly.com

    but not like this:

    Austin Sours

    Scenario: Specifying a Subelement That Occurs Zero or More Times
    Suppose you decide that the person’s name is sufficient information and that their e-mail 
    address is no longer required. You still want them to be able to submit one or more e-mail 
    addresses should they desire, but they are no longer necessary. In that case, your 


    - 75 -
    declaration would look like this:
    The parser now thinks that a user element is made of one name type element; none, one, 
    or several e-mail_address type elements; and one optional title element.
    Here’s what a valid user looks like:

    Austin Sours
    austins@being_silly.com
    austins@being_even_sillier.commail_address>
    International Man of Tartness

    It could also look like this:

    Austin Sours
    International Man of Tartness

    or even this:

    Austin Sours

    A nonvalid user
     
    element would look like this:

    austins@being_silly.com
    International Man of Tartness

    We just described most of the simple element type descriptions, and nothing is stopping 
    you from using more complicated combinations of the “zero or one” (?), “zero or more” 
    (*), and “one or more” (+) content model operators.
    Again, we recommend keeping things as simple as possible—we’re big fans of the KISS 
    (keep it short and simple) philosophy—but we realize some scenarios won’t let you do 
    that. Table 3.5 lists some examples of how you can make elements with more specialized 
    content models.

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




    Download 2,96 Mb.
    Pdf ko'rish

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Scenarios: Specifying Subelements That Occur at Least Once and

    Download 2,96 Mb.
    Pdf ko'rish