我正在開發可通過XML進行配置並可通過PowerShell模塊進行擴展的構建工具。我有一個XSD(http://download.crawler-lib.net/BuildTools/BuildConfig.xsd),它描述了開箱即用功能。正如前面的問題(Extending XML Schema xs:choice)所建議的,我想使用替換組以可擴展的方式映射我的工具。但是現在我有一個問題:有些工具只在某些地方有效。我怎樣才能以可擴展的方式將工具限制或映射到我的元素?XSD替代組n:m映射/多個替換組
硬編碼的,我會用<xs:choice>
定義在某些地方的工具。例如構建工具:
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element ref="bt:AppendText"/>
<xs:element ref="bt:Autover"/>
<xs:element ref="bt:Call"/>
<xs:element ref="bt:CopyFile"/>
<xs:element ref="bt:Download"/>
<xs:element ref="bt:DumpContext"/>
<xs:element ref="bt:FxCop"/>
<xs:element ref="bt:IntelliLock"/>
<xs:element ref="bt:MSBuild"/>
<xs:element ref="bt:NuGetPack"/>
<xs:element ref="bt:NuGetPush"/>
<xs:element ref="bt:NUnit"/>
<xs:element ref="bt:NuSpecUpdate"/>
<xs:element ref="bt:Powershell"/>
<xs:element ref="bt:RemoveFile"/>
<xs:element ref="bt:Upload"/>
<xs:element ref="bt:VerifyFile"/>
<xs:element ref="bt:Xslt"/>
<xs:element ref="bt:Zip"/>
</xs:choice>
憑據工具:
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element ref="bt:Powershell"/>
<xs:element ref="bt:File"/>
<xs:element ref="bt:Plain"/>
</xs:choice>
有共同PowerShell的工具。否則使用替代組是沒有問題的。所以我不知道如何以可重用的方式映射這些元素。
謝謝你的信息,我嘗試了一個稍微不同的方法。我定義了一個通用工具元素( )以及我需要特定工具的特定工具元素。 ( )。然後,我將選擇一般和特定的元素放在需要使用這些工具的地方。所以我擁有可以在任何地方工作的「通用」工具,以及用於構建步驟,標籤,版本等的特定工具。它不完全靈活,但其語義對我來說很有用。 –
2014-09-01 13:59:29