Working with XML: Well-Formed vs Valid
By SyncBuilder
XML has been around for decades, yet it remains central to a huge amount of integration work. If you exchange EDI documents, call SOAP web services, or read configuration and document formats, you are almost certainly working with XML every day.
Well-formed is not the same as valid
People often use these two words as if they mean the same thing, but they describe very different checks. Well-formed means the document follows the basic syntax rules of XML. Valid means it also conforms to a specific schema or DTD that defines which elements and attributes are allowed and how they must be arranged.
The rules for well-formed XML
- Every opening tag has a matching closing tag.
- There is exactly one root element that contains everything else.
- Tags are properly nested and never overlap.
- Every attribute value is wrapped in quotes.
- Special characters such as ampersand, less-than and greater-than are escaped as entities.
Being well-formed is not the same as being schema-valid. A file can be perfectly well-formed and still be rejected by your trading partner because it does not match the schema they expect.
Formatting also matters when you are debugging. Indenting turns deeply nested XML into something you can actually read, while minifying strips whitespace so the payload stays small for transport. Our free XML Formatter and Validator pretty-prints XML and checks well-formedness right in your browser.
Try the free tool