xsd - XML Schema: Define default value in child complextype -


we have parent element have "implementationclass" attribute. parent element have many children in define default value. here definition of parent element:

<xsd:complextype name="servicetype">     <xsd:sequence>         <xsd:element name="name" type="xsd:id" />         <xsd:element name="connection">             <xsd:complextype>                 <xsd:attribute name="reference" type="xsd:idref" use="required" />             </xsd:complextype>         </xsd:element>     </xsd:sequence>     <xsd:attribute name="implementationclass" type="xsd:string" use="optional" /> </xsd:complextype> 

to create child element, additionnal attribute, need use "extension". define default value, need use "restriction". however, these 2 mutually exclusive.

anybody can me figure out how that?

thanks in advance

you can achieve effects of both "extension" , "restriction" via intermediate type:

servicetype -> servicetypeintermediate -> servicetyperesult 

for example:

<xsd:complextype name="servicetypeintermediate">   <xsd:complexcontent>     <xsd:extension base="servicetype">       <xsd:sequence>         <xsd:element name="something" type="xsd:string"/>       <xsd:sequence>     <xsd:extension>   </xsd:complexcontent> </xsd:complextype>  <xsd:complextype name="servicetyperesult">   <xsd:complexcontent>     <xsd:restriction base="servicetypeintermediate">       ...     <xsd:restriction>   </xsd:complexcontent> </xsd:complextype> 

but please note following:

extension (of complex content) works new child elements (declared in it) added initial content sequence. is, cannot 'extend' children declared in base type.

in restriction, must define entire content model anew. new content must compatible 1 defined in base type.


Comments