Solved

Creating an unordered list of child elements (in dtd)

Posted on 2001-07-18
18
975 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 
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 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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The viewer will learn how to dynamically set the form action using jQuery.
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.

696 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