Jump to content

xs:decimal type can be nullable?


asaafj

Recommended Posts

Hi!I have a decimal element in my XML structure that is supposed to be optional. However, when trying to leave that element empty I get a SAXParseException:Caused by: org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: '' is not avalid value for 'decimal'.I need to put at least '0' (zero) in that element to pass...In the XSD I set a simpleType like this:<xs:simpleType name="dectype"> <xs:restriction base="xs:decimal"/></xs:simpleType>And where this "dectype" is used it is supposed to be optional (minOccurs="0"):<xs:complexType name="authorisationfeedbackitemtype"> <xs:sequence> <xs:element name="NotNullFreeTextField" minOccurs="1" maxOccurs="1" type="stringtype"/> <xs:element name="NullableFreeTextField" minOccurs="0" maxOccurs="1" type="stringtype"/> <xs:element name="NotNullFreeTextField" minOccurs="1" maxOccurs="1" type="stringtype"/> <xs:element name="NotNullFreeTextField" minOccurs="1" maxOccurs="1" type="stringtype"/> <xs:element name="NullableDecimalField" minOccurs="0" maxOccurs="1" type="dectype"/> <xs:element name="NullableFreeTextField" minOccurs="0" maxOccurs="1" type="stringtype"/> <xs:element name="NotNullDateField" minOccurs="1" maxOccurs="1" type="stringtype"/> <xs:element name="NullableFreeTextField" minOccurs="0" maxOccurs="1" type="stringtype"/> </xs:sequence></xs:complexType>Does "xs:decimal" expect a decimal value, I mean can't it be optional? I've tried to look around on the web and haven't found anything saying it's not possible. Or what else can be wrong?Thanks!

Link to comment
Share on other sites

Well, it really depends what you accept.Your current Schema accepts nothing or a single complete element. Scince it doesn't have anything else specified it won't match

<NullableDecimalField/>

nor

<NullableDecimalField></NullableDecimalField>

I think for both of those, you need to add nillable="true". So the line becomes

<xs:element name="NullableDecimalField" nillable="true" minOccurs="0" maxOccurs="1" type="dectype"/>

Link to comment
Share on other sites

Thanks for your answer! But... I tried to add 'nillable=true' in the xsd but it still won't accept no value in the NullableDecimalField. Tried to validate a test XML file with XML Spy, but it still says:"Invalid value for datatype decimal in element 'NullableDecimalField'"when I leave the field empty (like this: <NullableDecimalField></NullableDecimalField>)...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...