The rules
- A single root element contains everything else.
- Every opening tag is closed, in the right order.
- Attribute values are quoted.
- Special characters in text are escaped, for example
&for an ampersand. - Names are case-sensitive.
Well-formed versus valid
Well-formed is about syntax. Valid means the document also follows a schema or DTD that defines which elements are allowed. A file can be well-formed and still invalid for the system that reads it.
Try it
The XML Formatter checks whether your XML is well-formed and re-indents it. See how to format and validate XML.
Common misunderstanding
Ordinary HTML is usually not well-formed XML, since it allows unclosed tags such as a bare line break. XHTML is the strict version.