'In a DTD, can an attribute be in only one of two declared elements?
I have to write a DTD valid for this XML document:
<orders>
<order>
<_id ord_date="2020-03-01" status="A">1.0</_id>
<cust_id>Ant O. Knee</cust_id>
<items>
<element>
<price>2.5</price>
<qty>5.0</qty>
<sku>oranges</sku>
</element>
<element>
<price>2.5</price>
<qty>5.0</qty>
<sku>apples</sku>
</element>
</items>
<price>25.0</price>
</order>
<order>
<_id>3.0</_id>
<cust_id ord_date="2020-03-08" status="A">Busby Bee</cust_id>
<items>
<element>
<price>2.5</price>
<qty>10.0</qty>
<sku>oranges</sku>
</element>
<element>
<price>2.5</price>
<qty>10.0</qty>
<sku>pears</sku>
</element>
<element>
<price>0.0</price>
<qty>1.0</qty>
<sku>gift</sku>
</element>
<element>
<price>0.0</price>
<qty>1.0</qty>
<sku>gift</sku>
</element>
</items>
<price>50.0</price>
</order>
</orders>
As you can see, I have to declare the attribute ord_date and status inside _id or cust_id but it has to be in only one of those two.
I have tried to declare it like this, but this DTD allows to be in both, in one of them or in none of them.
<!ELEMENT orders(order)+>
<!ELEMENT order(_id, cust_id, items, price)>
<!ELEMENT _id>
<!ELEMENT cust_id (#PCDATA)>
<!ELEMENT items (element)+>
<!ELEMENT element (price, qty, sku)>
<!ELEMENT price>
<!ELEMENT qty>
<!ELEMENT sku (#PCDATA)>
<!ATTLIST _id ord_date CDATA #IMPLIED>
<!ATTLIST cust_id ord_date CDATA #IMPLIED>
How can I declare this DTD correctly?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
