473,383 Members | 1,877 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,383 software developers and data experts.

Enumerations with DTD's

I am creating an XML DTD, and I want to have an element that is
constrained to a set of enumerated values. My idea is to write my DTD
like this:

<!ELEMENT testEnum (mode)>
<!ELEMENT mode (mode_enabled | mode_disabled | mode_other)>
<!ELEMENT mode_enabled EMPTY>
<!ELEMENT mode_disabled EMPTY>
<!ELEMENT mode_other EMPTY>

Then an example XML document could look like this:

<?xml version="1.0" encoding="US-ASCII" standalone="yes"?>
<!DOCTYPE test>

<testEnum>
<mode>
<mode_disabled />
</mode>
</testEnum>

Is this a good way to do it? (Is there a standard way?) I welcome any
comments about it.

BTW, I am an XML newbie.

Thanks,
Norm

Oct 28 '05 #1
2 1914
Norm wrote:
I am creating an XML DTD, and I want to have an element that is
constrained to a set of enumerated values. My idea is to write my DTD
like this:

<!ELEMENT testEnum (mode)>
<!ELEMENT mode (mode_enabled | mode_disabled | mode_other)>
<!ELEMENT mode_enabled EMPTY>
<!ELEMENT mode_disabled EMPTY>
<!ELEMENT mode_other EMPTY>

Then an example XML document could look like this:

<?xml version="1.0" encoding="US-ASCII" standalone="yes"?>
<!DOCTYPE test>
You would need to specify where the processor is to find this object
"test", either by giving a SYSTEM URI for the DTD file, or by
providing the DTD in an internal subset, eg

<!DOCTYPE testEnum [
<!ELEMENT testEnum (mode)>
<!ELEMENT mode (mode_enabled | mode_disabled | mode_other)>
<!ELEMENT mode_enabled EMPTY>
<!ELEMENT mode_disabled EMPTY>
<!ELEMENT mode_other EMPTY>
]>
<testEnum>
<mode>
<mode_disabled />
</mode>
</testEnum>

Is this a good way to do it? (Is there a standard way?)


Yes, this works fine. There really isn't any other way to do this,
if you need the data structure to use elements (for example, if you
plan on giving mode_enabled etc some attributes or content of their
own).

An alternative is to use an attribute on the parent element type, eg

<!DOCTYPE testEnum [
<!ELEMENT testEnum (mode)>
<!ELEMENT mode EMPTY>
<!ATTLIST mode enabled (yes|no|other) #REQUIRED>
]>

This now lets you write

<testEnum>
<mode enabled="yes"/>
</testEnum>

You could make the #REQUIRED into a default value (eg "yes") if that
suits the data.

///Peter
--
XML FAQ: http://xml.silmaril.ie/

Oct 29 '05 #2
Thank you! That is what I needed to know.

-Norm

Oct 31 '05 #3

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

Similar topics

1
by: Joyce | last post by:
In my schema I have 2 enumerations, let's say, country description and country code, and I want to use them so I can map each country description to its precise country code (and no other). So far...
0
by: Plinkerton | last post by:
I'm making an Base Class that will be inherited. In my base class, I have a public enumeration that defines a list of things I want my class to be able to do. I use it for Method input...
21
by: Christopher Benson-Manica | last post by:
I'll try to explain what I want to do: I have foo.h and foo.cpp. Units that include foo.h will define an enumeration bar: enum bar { typeNone, typeBaz, typeQuux, ... , count }; A method...
3
by: JoeH | last post by:
Hi, I'm using a COM DLL (created in VB) in my javascript code and can successfully call its methods and get/set its properties. There are also some Public enumerations defined in the ActiveX...
1
by: someone else | last post by:
I have some code that creates dynamic enumerations for use in a PropertyGrid control. This all works perfectly but the memory usage of the program increases quite quicly when viewing the...
1
by: Oleg Ogurok | last post by:
Hi all, I've added a new DataSet (xsd file) to my project in VS.NET 2003. There I create a simple type as an enumeration of values. <xs:simpleType name="MyCustomType"> <xs:restriction...
4
by: ChrisB | last post by:
Hello: I will be creating 50+ enumerations related to a large number of classes that span a number of namespaces. I was wondering if there are any "best practices" when defining enumerations. ...
27
by: Ben Finney | last post by:
Antoon Pardon wrote: > I just downloaded your enum module for python > and played a bit with it. IMO some of the behaviour makes it less > usefull. Feedback is appreciated. I'm hoping to...
77
by: Ben Finney | last post by:
Howdy all, PEP 354: Enumerations in Python has been accepted as a draft PEP. The current version can be viewed online: <URL:http://www.python.org/peps/pep-0354.html> Here is the...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.