# The value is invalid according to its datatype

Source: https://xmlvalid.com/errors/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](/errors/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

libxml2, which xmlvalid validates with, reports it as [Is not a valid value of the atomic type](https://xmlvalid.com/errors/not-a-valid-value-of-the-atomic-type): `Element 'qty': 'two' is not a valid value of the atomic type 'xs:int'.`

## Example that fails

```xml
<order currency="EUR">
  <id>A-1</id>
  <qty>two</qty>
</order>
```

## Fixed

```xml
<order currency="EUR">
  <id>A-1</id>
  <qty>2</qty>
</order>
```
