DTD Logic

J

johnlittlepeap

how do all,

I have an xml file, for example
<content>
<section/>
<section/>
<on/>
<off/>
</content>

Obviously just an example. I would like the dtd to say, the xml file
must have one or more section, 0-1 on tags, 0-1 off tags and that the
on and off tags can be in any order. Try as I may I havn't been able
to uncover the syntax to define this.

I have at the moment

<!ELEMENT content (section+,on+,off+>

but the commas say they must be in that particular order, my xml files
aren't like this. I want to be pretty much as it is here, except that
they don't have to be in order. I don't want to just say ANY. Any help
would be appreciated

Troot
 
C

Charles Fineman

You can use alternation to get the order independence like so:

<!ELEMENT content (section|on|off)*>

But this does not solve your number-of-occurences constraint. Here is
another variation that ensures that the section is up front... still
does not strictly solve your number-of-occurences constraint:

<!ELEMENT content (section*, (on?|off?)*)>

To solve the constraint along with the order independence constraint,
you probably just need to do it by brute force:

<!ELEMENT content (section*, (on|off|(on,off)|(off,on)))>
 
O

Oliver Bonten

You can use alternation to get the order independence like so:

<!ELEMENT content (section|on|off)*>

But this does not solve your number-of-occurences constraint. Here is
another variation that ensures that the section is up front... still
does not strictly solve your number-of-occurences constraint:

<!ELEMENT content (section*, (on?|off?)*)>

To solve the constraint along with the order independence constraint,
you probably just need to do it by brute force:

<!ELEMENT content (section*, (on|off|(on,off)|(off,on)))>

That is actually not valid, because the content model is ambigous, which
is one of the more esoteric errors one can make in DTD design. Also, he
wanted "section" to be mandatory. I'd recommend:

<!ELEMENT content (section+, ((on,off?)?|off?)) >

Of course in an SGML DTD it would simply be:

<!ELEMENT content (section+, (on? & off?)) >

but the XML designers thought that no one ever really wants to use the "&"
connector.

Oliver
 
O

Oliver Bonten

That is actually not valid, because the content model is ambigous, which
is one of the more esoteric errors one can make in DTD design. Also, he
wanted "section" to be mandatory. I'd recommend:

<!ELEMENT content (section+, ((on,off?)?|off?)) >

I hate to correct myself, but probably

<!ELEMENT content (section+, ((on,off?)?|(off,on?)?)) >

would be more useful.

Oliver
 
J

johnlittlepeap

ah, I have more tags that need to have the same rule applied as on and
off. With only a couple more tags this becomes completly unworkable.
Thanks though for helping me. To be honest I thought something like
this might be the answer. Just hoped it wasn't.

Thanks

Troot
 

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,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top