xml - Change the restrictions of a simpletype element in child type -
i have type hierarchy in xsd following: type -> type b -> type c...
now type b defined like:
<xs:complextype name="typeb"> <xs:complexcontent> <xs:extension base="typea" > <xs:sequence> ... <xs:element name="elementa" minoccurs="0"> <xs:simpletype> <xs:restriction base="xs:int"> <xs:mininclusive value="0"/> <xs:maxinclusive value="10"/> </xs:restriction> </xs:simpletype> </xs:element> </xs:sequence> </xs:extension> </xs:complexcontent> </xs:complextype>
type c not need add elements type b defined like:
<xs:complextype name="typec"> <xs:complexcontent> <xs:extension base="typeb"> </xs:extension> </xs:complexcontent> </xs:complextype>
now restrictions type c elementa have changed - it's maxincluse should 5 not 10.
i can change type c changing type b should not break compatibility. there way change restrictions without breaking compatibility/the existing hierarchy?
you can declaring typec restriction of typeb , explicitly redefining complex content. however, work, need explicitly declare simple type restricts xs:int between 0 , 10, , explicitly restrict simple type changes maxinclusive 5. important simple type restriction explicit, explained here.
the schema so:
<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema"> <xs:element name="elementc" type="typec"/> <xs:complextype name="typea"> <xs:sequence> <xs:element name="foobar" type="xs:string"/> </xs:sequence> </xs:complextype> <xs:complextype name="typeb"> <xs:complexcontent> <xs:extension base="typea" > <xs:sequence> <xs:element name="elementa" type="type10" minoccurs="0"/> </xs:sequence> </xs:extension> </xs:complexcontent> </xs:complextype> <xs:simpletype name="type10"> <xs:restriction base="xs:int"> <xs:mininclusive value="0"/> <xs:maxinclusive value="10"/> </xs:restriction> </xs:simpletype> <xs:simpletype name="type5"> <xs:restriction base="type10"> <xs:maxinclusive value="5"/> </xs:restriction> </xs:simpletype> <xs:complextype name="typec"> <xs:complexcontent> <xs:restriction base="typeb"> <xs:sequence> <xs:element name="foobar" type="xs:string"/> <xs:element name="elementa" type="type5" minoccurs="0"/> </xs:sequence> </xs:restriction> </xs:complexcontent> </xs:complextype> </xs:schema>
and valid:
<?xml version="1.0" encoding="utf-8"?> <elementc xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:nonamespaceschemalocation="schema.xsd"> <foobar/> <elementa>5</elementa> </elementc>
and not:
<?xml version="1.0" encoding="utf-8"?> <elementc xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:nonamespaceschemalocation="schema.xsd"> <foobar/> <elementa>6</elementa> </elementc>
Comments
Post a Comment