tags:

views:

76

answers:

1

Hello, I extracted a xml fragment on which I am working for a DTD, pratically I need a specific declaration for resource contained in tag resources and another different one for resource contained in tag input. The problem is that the first one requires the id attribute, the second one does not require the id attribute because uses alternative attributes. Is it possible to declare something like (pseudocoded):

The xml fragment:

<xml>

  <resources>
    <resource id="somedir">sometpath</resource>
  </resources>

...

  <input>
    <resource exists="false">
      <path>somepath</path>
    </resource>
  </input>

</xml>

Is it possible with DTD or XSD?

Thanks

+1  A: 

With DTD - no, XSD - yes. Something like:

<xs:element name="root" type="r:rootType"/>
<xs:complexType name="rootType">
    <xs:sequence>
        <xs:element name="resources" type="r:resourcesType"/>
        <xs:element name="input" type="r:inputType"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="resourcesType">
    <xs:sequence>
        <xs:element name="resource" type="r:resourceType" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>
<xs:complexType name="inputType">
    <xs:sequence>
        <xs:element name="resource" type="r:inputResourceType" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>
...
lexicore