Due to my studies I'm learning about XML/DTD's. Now I've got an exercise in which I have to create an order. One point is, that I have 2 different types of customers. One student and one not student. This topic, I solved with a simple boolean.
<!ATTLIST Kunde isStudent (true | false) #REQUIRED>
But now I should display additional Elements if the customer is a Student. And if he's not, they aren't required.
My current structure is like this:
<!ELEMENT Customer (Name, Address)>
<!ATTLIST Customer isStudent (true | false) #REQUIRED>
<!--
If "isStudent === true" the Customer-Element should also have
<!ELEMENT StudentNumber (#PCDATA)>
<!ELEMENT UniversityName (#PCDATA)>
If "isStudent === false", they shouldn't/musn't be there
-->
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Adress (Street, Number, PLZ, City)>
<!ELEMENT Street (#PCDATA)>
<!ELEMENT Number (#PCDATA)>
<!ELEMENT PLZ (#PCDATA)>
<!ELEMENT City (#PCDATA)>
So I'm wondering... is it possible to create logic within dtd's? So like "If this is true, show this..." Or is the key to create the elements with the "?" flag?
No, DTDs aren't powerful enough to express such constraints. There are other XML schema technologies that can do it: RelaxNG, XSD 1.1 (but not 1.0), or Schematron, for example.