?

Log in

No account? Create an account
Andrei in the office

lordandrei

Andrei's Universe

One man's journey from infinity to nothingness


Previous Entry Share Flag Next Entry
Andrei in the office
lordandrei

DTD inquiry

This is cross-posted all over the place in the vain hope that someone might have an answer:

In DTD:

<!ELEMENT foo (bar)> means that a </font>foo</font> element can have only one </font>bar</font> sub-element.

<!ELEMENT foo (bar+)> means that a </font>foo</font> element must have at least one </font>bar</font> sub-element, it can have more.

<!ELEMENT foo (bar*)> means that a </font>foo</font> element may have at least one </font>bar</font> sub-element, it can have more, it can have none.

now:
<!ELEMENT foo (bar, gub)> means that a </font>foo</font> element must have only one </font>bar</font> sub-element that must be followed by a </font>gub</font> sub-element.

<!ELEMENT foo (bar | gub)> means that a </font>foo</font> element must have <strong></font>either</strong></font> one </font>bar</font> sub-element or one </font>gub</font> sub-element.

So...

if my </font>foo</font> element has 3 sub elements. Call them '</font>bar</font>, </font>gub</font>, and </font>kli</font>'. My constraints are. The sub elements must appear and must only appear once, but they can appear in any order.

You'd think:
<!ELEMENT foo (bar | gub | kli)+>
But that means: </font>foo</font> will have at least one sub element that could be any of the 3 choices.

I'd thought maybe:
<!ELEMENT foo ((bar) | (gub) | (kli))+>
But that seems to suffer from the previous problem.

Any takers?


  • 1
Don't know DTD.
But is there something like a logical AND which could allow you do to something like this:

AND AND ?

It's not in the definition. I posted a link to a basic tutorial of DTD over in the same thread in macosx

You say "DTD", I say "Schema"

Not quite what you asked for, but...

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="foo" type="fooType"/>
  <xsd:complexType name="fooType">
  <xsd:all>
    <xsd:element name="bar" type="xsd:string"/>
    <xsd:element name="gub" type="xsd:string"/>
    <xsd:element name="kli" type="xsd:string"/>
  </xsd:all>
</xsd:schema>


Looks like DTD language is lacking

But you can still do it:

<!ELEMENT foo (
    (bar, gub, kli) |
    (bar, kli, gub) |
    (gub, kli, bar) |
    (gub, bar, kli) |
    (kli, bar, gub) |
    (kli, gub, bar)
>>


  • 1