Reputation: 2681
I'm developing build tools that are configurable via XML and extendable with PowerShell modules. I have an XSD (http://download.crawler-lib.net/BuildTools/BuildConfig.xsd) which describes the out of the box functionality. As suggested in a previous question (Extending XML Schema xs:choice) I want to use substitution groups to map my tools in a extendable way. But now I have a problem: Some tools are only valid at certain places. how can I restrict or map the tools to my elements in a extendable way?
Hard coded I would use <xs:choice>
to define the tools on certain places. Eg the build tools:
<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>
the credentials tools:
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element ref="bt:Powershell"/>
<xs:element ref="bt:File"/>
<xs:element ref="bt:Plain"/>
</xs:choice>
have the Powershell tool in common. Otherwise it would be no problem to use a substitution group. So I don't know how to map these elements in a reusable way.
Upvotes: 0
Views: 501
Reputation: 163322
In XSD 1.0 substitution groups form a hierarchy, so this will only work if the sets of tools allowed in different places are simply nested. In XSD 1.1 elements can belong to more than one subtitution group, so you can (if it makes sense) map each such set to a substitution group (typically with an abstract element as its head) and define the membership specifically for each one. However, I would only be inclined to go this way if there is some natural semantics to the arrangement, that is if the tools form sets that can be described in a way that makes sense to the user.
Upvotes: 1