473,326 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

List of enumerated values as attributes

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.
Jun 27 '08 #1
4 1794
Are you using schemas, or DTDs? Either should be able to support this.
Jun 27 '08 #2
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.
Jun 27 '08 #3
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/
Jun 27 '08 #4
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.
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Simon | last post by:
Hi, I'm hoping you could show me examples of how a functional/declarative language could be used to consicely describe resticted subsets of elements. I'm looking for a 'specification' style...
22
by: Ben Finney | last post by:
Howdy all, I've recently packaged 'enum' in PyPI. In its description, I make the claim that it creates "immutable" enumeration objects, and that the enumeration values are "constant" values. ...
4
by: Shawnk | last post by:
This post is intended to verify that true value semantics DO NOT EXIST for the Enum class (relative to boolean operations). If this is true then (thus and therefore) you can not design state...
7
by: John Goche | last post by:
Hello, The following program compiler and runs fine under gcc and produces the output 3. However, I am not sure whether such behavior is legal. In particular, as a related question, how would I...
1
by: senfo | last post by:
I'm using an enumerated type to identify a record type that relates to a unique ID in a database. Identity columns in SQL start at 1, while enumerated types in C# start at 0. I didn't think it...
5
by: Nathan Harmston | last post by:
Hi, Sorry if the subject line of post is wrong, but I think that is what this is called. I want to create objects with class Coconuts(object): def __init__(self, a, b, *args, **kwargs):...
11
by: David Mathog | last post by:
Is there a standard compliant method to access the number of elements in an enumerated type in C, either from within the preprocessor or the running program? The example below compiles and runs...
2
by: Hulas | last post by:
I am designing a database prototype for my senior design class, and there are is a problem that I don't have any idea about where to even start. So, anybody out there, I will highly appreciate if you...
4
by: Rex the Strange | last post by:
Hello all, Can anyone please tell me why I can't do this (and what I can do to get the equivalent effect): In the code: public enum myenum value1 value2
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.