Thomas Maierhofer
Thomas Maierhofer

Reputation: 2681

Extending XML Schema xs:choice

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. One extension point are the tools of the build sequences:

  <xs:element name="BuildSequence">
    <xs:annotation>
      <xs:documentation>Performs a sequence of build tools to build the solution</xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <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:attribute name="Name" type="xs:string" use="required"/>
      <xs:attribute name="NewBuild" type="bt:boolean" use="optional"/>
    </xs:complexType>
  </xs:element>

Someone may extend this with an additional PowerShell module defining a build step tool named "MyTool". So in the XML config there may be another valid element which should be in the list of choices like:

<xs:element ref="custom:MyTool"/>

How can I extend such a definition with an additional (custom.xsd) XSD file? So that I get IntelliSense in Visual Studio for the custom element?

Upvotes: 0

Views: 219

Answers (1)

Michael Kay
Michael Kay

Reputation: 163272

Consider using substitution groups. If your content model allows element E, then it also allows any element that is in the substitution group of E; anyone can create such an element (unless you block it), and it automatically becomes available without having to change your content model.

Upvotes: 1

Related Questions