【发布时间】:2015-06-02 20:49:40
【问题描述】:
我的要求是有一个 XSD 文件,它可以根据属性值检查元素。我能够将 XSD 编写到可以限制Application/@Type 的属性值的程度。谁能帮我完成 XSD 文件,我可以根据Application/@Type 属性在其中制作一些所需的元素?
我想做
-
PackageArg仅当Application/@Type为“批处理”时才需要 -
Version仅当Application/@Type为“服务”时才需要 -
Project仅当Application/@Type是 Web 或“服务”时才需要
XML 文件
<Applications>
<Application Name="ConfigManagement" Type="Web">
<ProjectDirName>ConfigManagement</ProjectDirName>
<Project>Web.ConfigManagement.csproj</Project>
<OutputDirName>ConfigManagement</OutputDirName>
</Application>
<Application Name="Util" Type="Web">
<ProjectDirName>Web</ProjectDirName>
<Project>Web.csproj</Project>
<OutputDirName>Util</OutputDirName>
</Application>
<Application Name="ConfigService" Type="Service">
<ProjectDirName>WebServices\ConfigService</ProjectDirName>
<Project>ConfigService.csproj</Project>
<Version>2015\04</Version>
<OutputDirName>ConfigService</OutputDirName>
</Application>
<Application Name="DeliverEmail" Type="Batch">
<ProjectDirName>\Batch\DeliverEmail</ProjectDirName>
<PackageArg>Release</PackageArg>
<OutputDirName>Tidal\DeliverEmail</OutputDirName>
</Application>
</Applications>
XSD 文件
<xs:element name="Applications" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="Application" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:all>
<xs:element type="xs:string" name="ProjectDirName"/>
<xs:element type="xs:string" name="Project" minOccurs="0"/>
<xs:element type="xs:string" name="Version" minOccurs="0"/>
<xs:element type="xs:string" name="PackageArg" minOccurs="0"/>
<xs:element type="xs:string" name="OutputDirName"/>
</xs:all>
<xs:attribute type="xs:string" name="Name" use="optional"/>
<xs:attribute name="Type" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Web"/>
<xs:enumeration value="Batch"/>
<xs:enumeration value="Service"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
【问题讨论】:
-
请将您的链接材料直接添加到您的问题中。如果您提供了一个示例,说明您希望被视为有效的内容以及您希望被排除为无效的内容,这也会很有帮助。此外,请不要使用不是特定于您的问题的标签 - 这不是专门针对 C# 的问题。
-
@DanField 是对的——你的问题应该是独立的。这次我已经为您解决了这个问题,但请在以后的问题中包含所有需要的材料。谢谢。
-
感谢您的编辑和建议。下次我发布问题时,我会关注他们。