Edit online

Checking XML Well-Formedness

A Well-formed XML document is a document that conforms to the XML syntax rules. A Namespace Well-Formed XML document is a document that is Well-formed XML and is also Namespace-wellformed and Namespace-valid.

Well-Formedness Rules

The XML Syntax rules for Well-formed XML include:

  • All XML elements must have a closing tag.
  • XML tags are case-sensitive.
  • All XML elements must be properly nested.
  • All XML documents must have a root element.
  • Attribute values must always be quoted.
  • With XML, whitespace is preserved.

The Namespace-wellformed rules include:

  • All element and attribute names contain either zero or one colon.
  • No entity names, processing instruction targets, or notation names contain any colons.

The Namespace-valid rules include:

  • The xml prefix is by definition bound to the namespace name: http://www.w3.org/XML/1998/namespace. It MAY be declared, but MUST NOT be undeclared or bound to any other namespace name. Other prefixes MUST NOT be bound to this namespace name.
  • The xmlns prefix is used only to declare namespace bindings and is by definition bound to the namespace name: http://www.w3.org/2000/xmlns/. It MUST NOT be declared or undeclared. Other prefixes MUST NOT be bound to this namespace name.
  • All other prefixes beginning with the three-letter sequence x, m, l, in any case combination, are reserved. This means that users SHOULD NOT use them except as defined by later specifications and processors MUST NOT treat them as fatal errors.
  • The namespace prefix (unless it is xml or xmlns) MUST have been declared in a namespace declaration attribute in either the start tag of the element where the prefix is used or in an ancestor element (for example, an element in whose content the prefixed markup occurs). Furthermore, the attribute value in the innermost such declaration MUST NOT be an empty string.

Check for Well-Formedness

To check if a document is Namespace Well-Formed XML and Namespace-valid:
  • Select the Check Well-Formedness (Alt + Shift + V, W (Command + Option + V, W on macOS)) action from the Validation drop-down menu on the toolbar (or the XML menu).
  • A selection of files can be checked for well-formedness by selecting the Check Well-Formedness action from the Validate submenu when invoking the contextual menu in the Project Explorer view.

Result: If any errors are found, the result is displayed in the message panel at the bottom of the editor. Each error is displayed as one record in the result list and is accompanied by an error message. Clicking the record will open the document containing the error and highlight its approximate location.

Example: A non Well-formed XML Document
<root><tag></root>
When the Check Well-Formedness action is performed, the following error is displayed:
The element type "tag" must be terminated by the matching end-tag "</tag>"

To resolve the error, click the record in the resulting list and it will locate and highlight the approximate position of the error. In this case, identify the tag that is missing an end tag and insert </tag>.

Example: A non Namespace-wellformed Document
<prefix:elem></prefix:elem>
When the Check Well-Formedness action is performed, the following error is displayed:
The prefix "prefix" for element "prefix:elem" is not bound.
Example: A non Namespace-valid Document
<x:y></x:y>
When the Check Well-Formedness action is performed, the following error is displayed:
The prefix "x" for element "x:y" is not bound.