HTML and XML: related but different
HTML and XML both use angle-bracket tags, attributes, and nested elements, but they have different goals. HTML describes web pages and is deliberately forgiving: browsers follow the HTML Living Standard, which defines exactly how to recover from missing closing tags, misnested elements, and other mistakes. XML is a general data format used for feeds, SOAP services, office documents, SVG graphics, Android layouts, and many configuration files, and it is strict: a document with a single error is rejected.
Because of this difference, the same markup can display perfectly in a browser and still be invalid. A dedicated viewer helps you see both the structure a parser actually builds and the problems it found along the way.
Well-formed XML
An XML document is well-formed when it follows the basic grammar rules. There must be exactly one root element. Every opening tag needs a matching closing tag, or must be self-closing like <item/>. Elements must be properly nested, so <a><b></a></b> is an error. Tag names are case-sensitive, attribute values must always be quoted, and the same attribute cannot appear twice on one element.
Special characters must be escaped. A literal < or & in text must be written as < or &. Larger blocks of text containing many special characters can be wrapped in a CDATA section instead. Well-formedness is different from validity: a valid document is well-formed and also matches a schema, such as an XSD or DTD, that defines which elements and attributes are allowed.
Namespaces and declarations
The optional XML declaration at the top of a file states the version and encoding, for example UTF-8. If the declared encoding does not match the real bytes of the file, accented characters and symbols will appear garbled.
Namespaces let documents combine vocabularies without name clashes. A prefix such as soap: is bound to a URI with an xmlns:soap attribute, and elements with different prefixes are treated as completely different names even if their local names match. Many confusing XPath and parsing problems turn out to be namespace issues, so check the declarations first when a query returns nothing.
Inspecting HTML safely
Formatting minified HTML with consistent indentation makes the document structure readable, and a tree view shows how elements are really nested after parsing. That is often different from how the source looks, because browsers silently move or close elements. A paragraph cannot contain a div, for instance, so the parser closes the paragraph early.
Void elements such as br, img, input, and meta never have closing tags in HTML. Attribute quotes are optional in HTML but required in XML, so markup copied between the two often needs cleanup.
Rendering untrusted HTML is a security risk, because embedded scripts and event handler attributes can run code. A safe preview should sandbox the content or strip active elements before displaying it, and you should always inspect unknown markup as text before opening it in a full browser context.
Troubleshooting common markup errors
When an XML parser reports an error, start at the reported line and look for an unescaped ampersand, a missing closing tag, or a mismatched tag name that differs only in letter case. Errors such as content not allowed in prolog usually mean there is stray text, whitespace, or a byte order mark before the XML declaration.
For HTML, compare the source with the parsed tree. If an element appears in a different place than you wrote it, the parser has repaired invalid nesting, such as a block element inside a paragraph or a form inside another form. Fixing the source to match the parsed tree makes rendering predictable across browsers and easier to style.