validation - Definition of custom types as restriction within XML schema -


i writing generator source code (multiple languages). classes, i.e. basic data containers, should specified xml files. automatically validate , parse these xml files, defining xsd schema. should valid file:

<?xml version="1.0"?> <class>     <customtype name="vector3d">         <variable name="x" type="int"/>         <variable name="y" type="int"/>         <variable name="z" type="int"/>     </customtype>     <variable name="identifier" type="string"/>     <variable name="direction" type="vector3d"/> </class> 

i defined root element class, , elements customtype , variable as:

<xsd:complextype name="class">     <xsd:sequence>         <xsd:element name="customtype" type="customtype"             minoccurs="0" maxoccurs="unbounded"/>         <xsd:element name="variable" type="variable"             minoccurs="0" maxoccurs="unbounded"/>     </xsd:sequence> <xsd:complextype>  <xsd:complextype name="customtype">     <xsd:sequence>         <xsd:element name="variable" type="variable"             minoccurs="0" maxoccurs="unbounded"/>     </xsd:sequence>     <xsd:attribute name="name" type="xsd:string"         use="required"/> </xsd:complextype>  <xsd:complextype name="variable">     <xsd:attribute name="name" type="xsd:string"         use="required"/>     <xsd:attribute name="type" type="validtype"         use="required"/> </xsd:complextype> 

however, struggling heavily trying allow limited set of base types and names defined in customtype tags. defining set of base types easy:

<xsd:simpletype name="validtype">     <xsd:restriction base="xsd:string">         <xsd:enumeration value="bool"/>         <xsd:enumeration value="int"/>         <xsd:enumeration value="string"/>     </xsd:restriction> </xsd:simpletype> 

but there way can allow identifiers defined in name attribute of customtype tags, or have allow xsd:string , check validity within generator?

edit

if understood 3.16.2 of w3c xml schema definition language (xsd) recommendation correctly, want cannot done using xsd (because restrictions limited minexclusive | mininclusive | maxexclusive | maxinclusive | totaldigits | fractiondigits | length | minlength | maxlength | enumeration | whitespace | pattern | assertion | explicittimezone, not support kind of dynamic restriction), , have after validation of xsd schema manually.

can confirm correct?

yes think you're correct. in xsd 1.0 not possible make dynamic restrictions "if attribute name equals xx attribute type can equals zz". in xsd 1.1 there possibility define assertions i'm not sure how supported in available parsers (probably saxon have feature).


Comments