The value is invalid according to its datatype

A value is not in the format of its XML Schema datatype.

The message, as .NET reports it
The 'qty' element is invalid - The value 'two' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:int' - The string 'two' is not a valid Int32 value.

Why it happens

  • A number with a decimal comma, a thousands separator or a unit; a date in a local format (xs:date is 2026-10-17).
  • An empty element for a numeric or date type.
  • The same message for an attribute starts The 'qty' attribute is invalid.

How to fix it

The last part of the message says what is wrong with the value: write it in the datatype's format. A facet adds its own ending instead, such as The Enumeration constraint failed.

.NET throws an XmlSchemaValidationException at the first schema error unless XmlReaderSettings.ValidationEventHandler is set, which then receives every one with its line and position. A well-formedness error is an XmlException and ends reading whatever the settings.

The same problem in xmlvalid

xmlvalid validates with libxml2, which reports it as Is not a valid value of the atomic type. It checks the whole document in your browser and lists every schema error with its line and column, not only the first.

Element 'qty': 'two' is not a valid value of the atomic type 'xs:int'.

Example

Validated against order.xsd, below.

Reports the error
<order currency="EUR">
  <id>A-1</id>
  <qty>two</qty>
</order>
Fixed
<order currency="EUR">
  <id>A-1</id>
  <qty>2</qty>
</order>
order.xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="order">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="id" type="xs:string"/>
        <xs:element name="qty" type="xs:int"/>
        <xs:element name="status" type="Status" minOccurs="0"/>
        <xs:element name="code" type="Code" minOccurs="0"/>
        <xs:element name="note" type="Short" minOccurs="0"/>
      </xs:sequence>
      <xs:attribute name="currency" type="xs:string" use="required"/>
    </xs:complexType>
  </xs:element>
  <xs:simpleType name="Status">
    <xs:restriction base="xs:string">
      <xs:enumeration value="open"/>
      <xs:enumeration value="paid"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="Code">
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Z]{3}-[0-9]{4}"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="Short">
    <xs:restriction base="xs:string">
      <xs:maxLength value="10"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>