I need to create DTD or XMLSchema. How do i link elements collection@key="role" with collection@key="tie"? Is this possible or do they need to be done in different elements?
I have XML
<!DOCTYPE schema [
<!ELEMENT schema (collection+, part+)>
<!ELEMENT collection[key=role] (name, partref+)>
<!ATTLIST collection[key=role] collection-id ID #REQUIRED
key CDATA #REQUIRED>
<!ELEMENT name (#PCDATA)>
<!ELEMENT partref EMPTY>
<!ATTLIST partref refid IDREF #REQUIRED>
<!ELEMENT collection[key=tie] (name)>
<!ATTLIST collection[key=tie] part-id ID #REQUIRED>
]>
<schema>
<collection collection-id="C28392-33-TT" key="role">
<name>Turnip Twaddler</name>
<partref refid="P81952-26-PK"/>
<partref refid="P86679-52-SP"/>
<partref refid="P81472-68-FD"/>
<partref refid="P88107-39-GT"/>
</collection>
<collection collection-id="C28772-63-OB" key="role">
<name>Olive Bruiser</name>
<partref refid="P80228-21-PT"/>
<partref refid="P82387-85-PA"/>
</collection>
<part part-id="P80228-21-PT">
<name>Pitter</name>
</part>
<collection part-id="P86994-25-RC" key="tie">
<name>Ribbon Curler</name>
</collection>
</schema>
In a DTD, you can define an attribute as being an ID and another as being an IDREF; ID values must be unique in the document, and IDREF values must "point to" an ID that exists in the document.
But you can't have two different content models for the same element name, so the type of an attribute can't depend on where it appears.
In XSD, you CAN have two different content models for the same element name, by defining local element declarations; but you can't do it if they appear as siblings (children of the same parent element).