List of enumerated values as attributes

Discussion in 'XML' started by Olivier Lefevre, May 7, 2008.

  1. I want to define an attribute as a list of values taken from a finite set,
    with a singleton default. Intuitively I want to write

    attrname (AA|BB|CC)* "AA"

    but that is not valid syntax and I can't find a way. Any suggestion? Or
    am I out of luck?

    Thanks,

    -- O.L.
     
    Olivier Lefevre, May 7, 2008
    #1
    1. Advertising

  2. Are you using schemas, or DTDs? Either should be able to support this.
     
    Joseph J. Kesselman, May 7, 2008
    #2
    1. Advertising

  3. Hmmm. The default isn't a problem. DTDs can't express the value
    constraint you describe, but schemas should be able to do so -- via a
    regular expression if nothing else.
     
    Joseph J. Kesselman, May 7, 2008
    #3
  4. Olivier Lefevre

    Peter Flynn Guest

    Olivier Lefevre wrote:
    > I want to define an attribute as a list of values taken from a finite
    > set, with a singleton default. Intuitively I want to write
    >
    > attrname (AA|BB|CC)* "AA"
    >
    > but that is not valid syntax and I can't find a way. Any suggestion? Or
    > am I out of luck?


    No, but as you found, it won't work using a token list enumeration.

    However, it will work if you define dummy external non-XML entities for
    the values you want to use, and declare the attribute as type ENTITIES.

    <?xml version="1.0"?>
    <!DOCTYPE test [
    <!ELEMENT test EMPTY>
    <!ATTLIST test stuff ENTITIES "foo">
    <!NOTATION NONXML SYSTEM "nonxml">
    <!ENTITY foo SYSTEM "foo" NDATA NONXML>
    <!ENTITY bar SYSTEM "bar" NDATA NONXML>
    <!ENTITY blort SYSTEM "blort" NDATA NONXML>
    ]>
    <test stuff="bar blort"/>

    Note that the SYSTEM identifiers for the NOTATION and ENTITY
    declarations are not resolved (so your parser will not try to find or
    open them as URIs or local files).

    It would also work using the attribute type IDREFS, and then you
    wouldn't need to make the dummy NOTATION and ENTITY declarations, but
    you would have to have a suitable unused ID attribute on some element
    type somewhere, and you would have to add matching ID instances to
    sufficient occurrences of the bearer element type to satisfy the ID
    constraint. Using the above technique is probably easier.

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/
     
    Peter Flynn, May 7, 2008
    #4
  5. Peter Flynn wrote:
    > However, it will work if you define dummy external non-XML entities for
    > the values you want to use, and declare the attribute as type ENTITIES.


    OK, that's a clever workaround... and may be the first good use I've
    seen for the ENTITIES type.
     
    Joseph J. Kesselman, May 7, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cristian
    Replies:
    6
    Views:
    1,521
    David R Brooks
    Oct 13, 2004
  2. Marek Ponca

    Enumerated Type in assertion ?

    Marek Ponca, Jan 10, 2005, in forum: VHDL
    Replies:
    2
    Views:
    3,337
    Jonathan Bromley
    Jan 10, 2005
  3. Replies:
    3
    Views:
    406
  4. Kevin Neilson

    Assigning Values to Enumerated Types

    Kevin Neilson, May 7, 2008, in forum: VHDL
    Replies:
    9
    Views:
    612
    Kevin Neilson
    May 9, 2008
  5. Hobo
    Replies:
    0
    Views:
    336
Loading...

Share This Page