xsd validation - xml doesnt match xsd schema - why? -
i need xml match xsd schema doesnt match. can wrong in xsd schema? not right xsi:type="...". may miss something. hope can notice wrong. have been trying use xsd validate online , fix doesnt work. give , decide write here. appreciated. thanks!
here xml:
<?xml version="1.0" encoding="utf-8" ?> <validatorlist xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" > <fieldvalidator xsi:type="requiredfieldvalidator" propertyname="banktransactionnumber"> <next xsi:type="asciivalidator" /> </fieldvalidator> <fieldvalidator xsi:type="requiredfieldvalidator" propertyname="currencyindicator"> <next xsi:type="stringlengthvalidator" maxlength="3" minlength="3"> <next xsi:type="alphavalidator" /> </next> </fieldvalidator> </validatorlist>
xsd schema xml:
<xs:schema attributeformdefault="unqualified" elementformdefault="qualified" xmlns:xs="http://www.w3.org/2001/xmlschema"> <xs:element name="validatorlist"> <xs:complextype> <xs:sequence> <xs:element name="fieldvalidator" maxoccurs="unbounded" minoccurs="0"> <xs:complextype mixed="true"> <xs:sequence> <xs:element name="next" minoccurs="0"> <xs:complextype mixed="true"> <xs:sequence> <xs:element name="next" minoccurs="0"> <xs:complextype mixed="true"> <xs:sequence> <xs:element name="next" minoccurs="0"> <xs:complextype> <xs:simplecontent> <xs:extension base="xs:string"> <xs:attribute type="xs:byte" name="decimalplaces"/> </xs:extension> </xs:simplecontent> </xs:complextype> </xs:element> </xs:sequence> <xs:attribute type="xs:byte" name="maxlength" use="optional"/> <xs:attribute type="xs:byte" name="minlength" use="optional"/> <xs:attribute type="xs:string" name="allowedvalues" use="optional"/> </xs:complextype> </xs:element> </xs:sequence> <xs:attribute type="xs:byte" name="maxlength" use="optional"/> <xs:attribute type="xs:byte" name="minlength" use="optional"/> <xs:attribute type="xs:byte" name="defaultvalue" use="optional"/> </xs:complextype> </xs:element> <xs:element type="xs:string" name="regex" minoccurs="0"/> </xs:sequence> <xs:attribute type="xs:string" name="propertyname" use="optional"/> <xs:attribute type="xs:byte" name="defaultvalue" use="optional"/> <xs:attribute type="xs:string" name="typeproperty" use="optional"/> <xs:attribute type="xs:string" name="regex" use="optional"/> </xs:complextype> </xs:element> </xs:sequence> </xs:complextype>
i got error message this:
error - line 4, 39: org.xml.sax.saxparseexception; linenumber: 4; columnnumber: 39; cvc-elt.4.2: cannot resolve 'asciivalidator' type definition element 'next'. error - line 6, 87: org.xml.sax.saxparseexception; linenumber: 6; columnnumber: 87; cvc-elt.4.2: cannot resolve 'requiredfieldvalidator' type definition element 'fieldvalidator'. error - line 7, 72: org.xml.sax.saxparseexception; linenumber: 7; columnnumber: 72; cvc-elt.4.2: cannot resolve 'stringlengthvalidator' type definition element 'next'. error - line 8, 41: org.xml.sax.saxparseexception; linenumber: 8; columnnumber: 41; cvc-elt.4.2: cannot resolve 'alphavalidator' type definition element 'next'.
the xsi:type
attribute intended used when have hierarchy of named types in schema , element declared type base type actual type 1 of derived types. archetypal example address
type subtypes usaddress
, ukaddress
in schema fieldvalidator
, next
elements declared using anonymous nested <complextype>
definitions rather named types, there's no way have other types derived these, no sense in using xsi:type
. structure schema differently, using top-level named types:
<xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema"> <xs:complextype name="fieldvalidatortype"> <xs:sequence> <xs:element name="next" type="fieldvalidatortype" minoccurs="0" /> </xs:sequence> <xs:attribute name="propertyname" type="xs:string" use="optional" /> </xs:complextype> <xs:complextype name="requiredfieldvalidator"> <xs:complexcontent> <xs:extension base="fieldvalidatortype" /> </xs:complexcontent> </xs:complextype> <xs:complextype name="asciivalidator"> <xs:complexcontent> <xs:extension base="fieldvalidatortype" /> </xs:complexcontent> </xs:complextype> <xs:complextype name="stringlengthvalidator"> <xs:complexcontent> <xs:extension base="fieldvalidatortype"> <xs:attribute type="xs:byte" name="maxlength" use="optional"/> <xs:attribute type="xs:byte" name="minlength" use="optional"/> </xs:extension> </xs:complexcontent> </xs:complextype> <!-- , similar complextype declarations other types such alphavalidator --> <xs:element name="validatorlist"> <xs:complextype> <xs:sequence> <!-- define fieldvalidator element referring base fieldvalidatortype, instance documents can use xsi:type substitute subtypes such stringlengthvalidator --> <xs:element name="fieldvalidator" maxoccurs="unbounded" minoccurs="0" type="fieldvalidatortype" /> </xs:sequence> </xs:complextype> </xs:element> </xs:schema>
as making xsi:type
attributes work properly, has advantage of tying different facets respective validator types (e.g. maxlength
valid stringlengthvalidator
) , supporting arbitrary depths of next
nesting (because type definition recursive).
Comments
Post a Comment