-1

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>
MFS
  • 9
  • 2
  • Sorry, but working out your requirements from code written in a language that you seem to have invented yourself isn't easy. I don't understand what you mean by "linking" two elements, I don't understand the `[...]` notation in your pseudo-DTD, and I don't know what constraints you want to impose. Downvoting. – Michael Kay Jan 31 '20 at 09:59
  • Sorry for the confusion ATTLIST collection [key = tie] part-id ID #REQUIRED this is an incorrect code, I wanted to show them that the value of the attribute is equal to the value of the attribute. So they are connected, but I don’t know how to reflect it in DTD – MFS Jan 31 '20 at 11:58

1 Answers1

0

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).

Michael Kay
  • 156,231
  • 11
  • 92
  • 164