?
Solved

Creating an unordered list of child elements (in dtd)

Posted on 2001-07-18
18
Medium Priority
?
1,005 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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:Wayne Bradney
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:Wayne Bradney
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:Wayne Bradney
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:Wayne Bradney
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:
Wayne Bradney earned 400 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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

864 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