Solved

Creating an unordered list of child elements (in dtd)

Posted on 2001-07-18
18
965 Views
Last Modified: 2013-11-19
Hello
Example below demonstrate unordered set of child elements:
<!ELEMENT MyList (a | b | c)+>
Each element can appear at least once (1 or more).

How can I create an unordered list of child elements: each element can appear only once or none (is optional) !

In another words: list of optional elements, but each element can appear max only once.
Alex
0
Comment
Question by:apsoft
  • 5
  • 4
  • 4
  • +4
18 Comments
 
LVL 10

Expert Comment

by:Yury_Delendik
ID: 6297452
<!ELEMENT MyList ((a , ((b , c?) | (c , b?))?) | (b , ((a , c?) | (c , a?))?) | (c , ((a , ((b , c?) | (c , b?))?) | (b , ((a , c?) | (c , a?))?) | (c , ((a , b?) | (b , a?))?))))? >
0
 
LVL 4

Expert Comment

by:chabaud
ID: 6297546
for short:

<!ELEMENT MyList (
(a , ((b , c?) | (c , b?))?) |
(b , ((a , c?) | (c , a?))?) |
(c , ((a , b?) | (c , a?))?)
) >
0
 

Author Comment

by:apsoft
ID: 6297651
Oh, it is too complicated.

And what, if there are 20, or more, elements in this list
<!ELEMENT MyList (a | b | c | d | e | f | g | h | i | j ... etc. )+>

?

Alex
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6298317
Time to do some data modeling  :)
0
 
LVL 10

Expert Comment

by:Yury_Delendik
ID: 6298440
<script>
var a = new Array("a", "b", "c", "d", "e", "f", "g", "h");
function generate(p) {
  if(p == a.length - 1) return a[p] + "?";
  var s = "(" + a[p] + ", " + generate(p + 1) + ")";
  for(var i=p + 1;i<a.length;++i) {
    var t = a[p]; a[p] = a[i]; a[i] = t;
    s += "|(" + a[p] + ", " + generate(p + 1) + ")";
  }
  return "(" + s + ")?";
}

document.write(generate(0));
</script>
0
 
LVL 6

Expert Comment

by:wbradney
ID: 6299113
apsoft,

Use XML Schemas instead?

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns='http://www.w3.org/2001/XMLSchema'>

 <element name="MyList">
  <complexType>
   <all>
     <element name="A" minOccurs="0"/>
     <element name="B" minOccurs="0"/>
     <element name="C" minOccurs="0"/>
   </all>
  </complexType>
 </element>

</schema>

Regards,
WMB
0
 

Expert Comment

by:Centrogen
ID: 6321065
I am sorry.. but won't this work?
<!ELEMENT MyList (a | b | c)?>
0
 
LVL 2

Expert Comment

by:djokov
ID: 6340809
Or what about this:
<!ELEMENT MyList (a? | b? | c?)+>
0
 

Author Comment

by:apsoft
ID: 6347622
Legal sequences are (for 3 elements):
1. a
2. a,b
3. a,c
4. a,b,c
5. b,c
6. c

To: Centrogen
In your example I can use only one element in sequence!

To: djokov
In your example legal are too:
a,b,a
and it is incorect sequence.

To: wbradney
It is ok, I know.
But I will use only one solutions for all my projects.

To: Yury_Delendik
You solution is clever, but not aceptable.
:)

To: Dave_Greene
Too expensive.

Alex
0
 
LVL 2

Expert Comment

by:djokov
ID: 6347661
Legal sequences are (for 3 elements):
1. a
2. a,b
3. a,c
4. a,b,c
5. b,c
6. c

and
7. b

<!ELEMENT MyList (a? | b? | c?)+> is correct as
? means 0 or 1 times. I don't see how a,b,a could happen.

0
 
LVL 6

Expert Comment

by:wbradney
ID: 6348674
djokov,

I'm not a DTD expert, but doesn't ()+ mean that the whole group (in parenths) must appear one or more times? If so, some valid sequences for (a? | b? | c?)+ are:

a b c
a b c a b c
a b a b a b c
a a a a a a ....
b b a a c c a c b a c b a

Regards,
WMB
0
 
LVL 2

Expert Comment

by:djokov
ID: 6348769
ok, i just cutted and pasted apsoft's example, it should be
<!ELEMENT MyList (a? | b? | c?)>
0
 

Author Comment

by:apsoft
ID: 6348882
To: djokov  
Yes, and
7. b :)

To: wbradney
Yes, exactly !
So, what about my problem: How can I create an unordered list of child elements: each element can appear only once or none (in dtd) !
Alex
0
 
LVL 6

Expert Comment

by:wbradney
ID: 6348914
djokov,

(a? | b? | c?) doesn't allow for, eg:

c b a
b c
c b

In fact, I think your solution only allows for the following four sequences:

1. a by itself
2. b by itself
3. c by itself
4. nothing at all (empty content)

apsoft,

I think that with DTDs, Yuri's is the only solution, but
XML Schema allows you to express these types of content models in a much cleaner fashion.

Regards,
WMB
0
 
LVL 2

Expert Comment

by:djokov
ID: 6348930
ok, sorry, i missunderstood this question
0
 
LVL 6

Expert Comment

by:wbradney
ID: 6348942
apsoft,

>>Legal sequences are (for 3 elements):
>>1. a
>>2. a,b
>>3. a,c
>>4. a,b,c
>>5. b,c
>>6. c

Be careful, that's not what you originally asked for:

>>How can I create an unordered list of child elements: each element can appear only once or none (is
optional) !

In this case, all 16 valid sequences are:

1. Nothing (empty content)
2. a
3. b
4. c
5. a b
6. a c
7. a b c
8. a c b
9. b a
10. b c
11. b a c
12. b c a
13. c a
14. c b
15. c a b
16. c b a

Regards,
WMB
0
 

Author Comment

by:apsoft
ID: 6349092
To: wbradney
Yes, you are right !
There are more then 7 valid poossible sequences.
Sorry.

Alex
0
 
LVL 6

Accepted Solution

by:
wbradney earned 200 total points
ID: 6349358
apsoft,

Yours is one of the many situations that XML Schema was designed to resolve. And since it's now a W3C Recommendation, unless there's a compelling reason to stick with DTD, you really should take a look.

Remember that most parsers now can validate against both DTDs and XML Schemas, and the good ones (like Apache Xerces) allow you to override the parser functions that resolve namespaces and grammars, so that you can gradually make the switch without affecting your partner systems' output.

Regards,
WMB
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question