What counts as well-formed XML?
- One root element wraps everything else.
- Every opening tag has a matching closing tag, or is self-closing like
<br/>, and tags close in the right order. - Attribute values are in quotes, and an attribute appears only once per element.
- Special characters in text are escaped:
<for < and&for &, or wrapped in<![CDATA[ … ]]>.
The validator checks all of these and reports the line and column of the first problem. It does not check against a DTD or XML Schema.
How XML maps to JSON
| XML | JSON |
|---|---|
<title>Rain</title> | "title": "Rain" |
<book id="1"> | "book": { "@id": "1" } |
| Text next to child elements or attributes | "#text": "…" |
Repeated <tag> elements | An array: "tag": ["a", "b"] |
Values stay as text, because XML has no number type. Converting JSON back to XML follows the same rules, so the two directions round-trip.