Solved

Creating an unordered list of child elements (in dtd)

Posted on 2001-07-18
18
967 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

738 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