Viper
Viper

Reputation: 2236

XSD validation fails because null value is invalid decimal

i have a problem writing a valid XSD which describes a potential null-value for a decimal.

I'm trying to validate following XML

<RatioDe fieldId="011" nil="true"></RatioDe>

and the corresponding XSD description for this element is

  <xs:element minOccurs="0" maxOccurs="1" name="RatioDe" nillable="true">
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="xs:decimal">
          <xs:attribute name="fieldId" type="xs:string" />
          <xs:attribute name="nil" type="xs:boolean" />
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>

Basically, the errormessage is

The element 'RatioDe' is invalid - The value '' is not a valid 'Decimal' -- The string '' is not a valid decimal value

At the moment i have no further idea what to change in my xsd to make the xml valid.

Upvotes: 1

Views: 5215

Answers (1)

skaffman
skaffman

Reputation: 403581

You need to use xsi:nil in your instance document, not just nil, i.e.

<RatioDe fieldId="011" xsi:nil="true"/>

And make sure that the xsi prefix is defined somewhere in the document (with xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance")

Upvotes: 2

Related Questions