Well the W3C XSD schema language has no instructions to generally specify the presence of one attribute based on the value of another attribute. The language however allows you to define types and to extend or restrict such types. For your particular example you could first define a type alike
<xs:simpleType name="TargetType"> <xs:restriction base="xs:string"> <xs:enumeration value="File"/> <xs:enumeration value="Stream"/> </xs:restriction> </xs:simpleType>
<xs:complexType name="LinkType"> <xs:attribute name="Target" type="TargetType" use="required"/> <xs:attribute name="Filename" type="xs:string" use="optional"/> </xs:complexType>
which makes the Filename attribute optional, then you could restrict that type alike
<xs:complexType name="FileLinkType"> <xs:complexContent> <xs:restriction base="LinkType"> <xs:attribute name="Target" type="TargetType" use="required" fixed="File"/> <xs:attribute name="Filename" type="xs:string" use="required"/> </xs:restriction> </xs:complexContent> </xs:complexType>
where the Target attribute value is fixed as "File" and then the Filename attribute is required. However in any instance XML document you would then need e.g.
<Link xsi:type="FileLinkType" Target="File" Filename="file.xml"/>
to require the restricted type and enforce the constraints during validation.
|