Well-formed and valid are different tests
Well-formed means the syntax is correct: one root element, every tag closed, attributes quoted, reserved characters escaped. Valid means the document also conforms to a schema — a DTD, XSD, or Relax NG — that says which elements may appear where. A document can be perfectly well-formed and still wrong for its purpose.