开发者

DTD (or XSD) problem with duplicate name element having different scopes

开发者 https://www.devze.com 2022-12-25 03:39 出处:网络
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 inp

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 re开发者_StackOverflowquire 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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号