# cvc-type.3.1.3 / cvc-datatype-valid.1.2.1: invalid value

These two Xerces messages can describe one bad value at different levels. cvc-datatype-valid.1.2.1 identifies a lexical value that does not belong to the selected atomic datatype. cvc-type.3.1.3 then reports the containing element’s value as invalid.

## Literal meaning

The text two cannot be interpreted as an xs:integer. Xerces reports both the datatype failure and the element-value failure for count, while other engines may issue only one diagnostic. Replacing two with 2 repairs the lexical representation without altering the declaration or switching the type to string.

## Three common causes

1. Human-readable formatting entered a machine-readable field. Words, thousands separators or locale-specific decimal punctuation can be invalid for the declared XSD datatype.
2. An empty or whitespace-only element was emitted for a required numeric or date value. Presence of a tag does not manufacture a valid typed value.
3. The producer uses a different type contract from the receiver. A decimal-looking identifier or timestamp may be legal text but incompatible with the type selected in this schema version.

## Repair

Read the earliest datatype or facet diagnostic before the broader element-value message. Extract the exact text after XML entity expansion and whitespace processing, then compare it with the declared simple type and its base. Correct serialization at the field boundary. Preserve the schema’s meaning: changing xs:integer to xs:string would discard numeric validation rather than repair the export.

## Namespace checks

This example reaches the correct count declaration, so its failure is not caused by a missing namespace. Namespaces matter when xsi:type selects another type or the document is validated against an unintended vocabulary. If the reported type surprises you, trace type selection before editing values.

A paired Xerces report is not evidence of two independent corrupt fields. In the transcript both messages refer to count and disappear together after one text change. If the value already belongs to the base datatype, inspect restriction facets such as pattern, enumeration and length instead of forcing a numeric conversion.

## Invalid datatype / cvc-type.3.1.3 — Broken

```xml
<count>two</count>
```

```xml
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="count" type="xs:integer"/>
</xs:schema>
```

[Open broken pair](https://xsdhub.com/?example=parser-datatype&variant=bad#workbench)

## Invalid datatype / cvc-type.3.1.3 — Corrected

```xml
<count>2</count>
```

```xml
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="count" type="xs:integer"/>
</xs:schema>
```

[Open corrected pair](https://xsdhub.com/?example=parser-datatype&variant=good#workbench)

### Apache Xerces-J 2.12.2

```text
cvc-datatype-valid.1.2.1: 'two' is not a valid value for 'integer'.
cvc-type.3.1.3: The value 'two' of element 'count' is not valid.
```

Corrected: PASS.

### .NET 8.0.33 · System.Xml.Schema

```text
The 'count' element is invalid - The value 'two' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:integer' - The string 'two' is not a valid Integer value.
```

Corrected: PASS.

### XSDHub libxml2/WASM 0.7.2

```text
Element 'count': 'two' is not a valid value of the atomic type 'xs:integer'.
```

Corrected: PASS.

### XSDHub xmlschema 4.3.1 · XSD 1.0

```text
invalid literal for int() with base 10: 'two'
```

Corrected: PASS.

Saxon EE was not available; no measured Saxon wording is claimed.

[All parser codes](https://xsdhub.com/learn#parser-error-codes)
[Download engine evidence](https://xsdhub.com/parser-error-examples/engine-evidence.json)
