Solved

Creating an unordered list of child elements (in dtd)

Posted on 2001-07-18
18
953 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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)

746 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now