# cvc-complex-type.2.3: Element cannot have character [children]

Source: https://xmlvalid.com/errors/cvc-complex-type-2-3

> Text appears directly inside an element that may only contain other elements.

The message, as Java reports it: `cvc-complex-type.2.3: Element 'order' cannot have character [children], because the type's content type is element-only.`

## Why it happens

- Stray text between child elements: a value typed outside its element, a leftover word.
- A value written straight into the parent instead of into the child element meant for it.
- Characters that look like whitespace but aren't, such as a non-breaking space, between elements.

## How to fix it

- Find the text directly inside the element the message names and move it into the right child, or delete it. Plain spaces and line breaks between elements are fine; anything else is not.
- Java's schema validation (`javax.xml.validation.Validator`, and JAXB or Spring on top of it) throws at the first error unless you set an `ErrorHandler` whose `error()` records the `SAXParseException` and carries on; each one has `getLineNumber()` and `getColumnNumber()`. A well-formedness error ends parsing whatever the handler does.

## The same problem in xmlvalid

libxml2, which xmlvalid validates with, reports it as [Character content other than whitespace is not allowed](https://xmlvalid.com/errors/character-content-element-only): `Element 'order': Character content other than whitespace is not allowed because the content type is 'element-only'.`

## Example that fails

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

## Fixed

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