List of enumerated values as attributes

  • Thread starter Olivier Lefevre
  • Start date
O

Olivier Lefevre

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.
 
J

Joseph J. Kesselman

Are you using schemas, or DTDs? Either should be able to support this.
 
J

Joseph J. Kesselman

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.
 
P

Peter Flynn

Olivier said:
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
 
J

Joseph J. Kesselman

Peter said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top