Skip to main content
XMLDir

Search 309 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

Document syntax

Prolog

Everything in a document before the root element's start tag: the XML declaration, any comments or processing instructions, and the document type declaration.

The prolog is optional in its entirety — a document that begins directly with its root element is perfectly well-formed. What is not optional is the order. If an XML declaration is present it must be the very first thing in the file, before any whitespace, comment or byte other than a byte order mark.

That ordering rule causes one of the most common failures in generated XML. A template that emits a blank line, a licence comment, or a stray newline before the declaration produces a document no conforming parser will read, and the message names the declaration rather than the whitespace that displaced it.

Defined in
XML 1.0 §2.8
Category
Document syntax
Also written
document prolog, XML header

Shown, not asserted

All 2 claims are executed on every test run, against the same engines the tools use. If the behaviour changes, the test fails rather than this page quietly becoming wrong.

  • A prolog is optional: a document may begin with its root element.

    document.xml
    <greeting>hello</greeting>

    What the engine returns

    Well-formed.
  • But if a declaration is present, nothing may come before it — not even a newline.

    document.xml
    
    <?xml version="1.0" encoding="UTF-8"?>
    <greeting>hello</greeting>

    What the engine returns

    XML declaration allowed only at the start of the document (line 2)

What catches people out

  • A leading blank line is invisible in most editors and fatal to the parser. If your build concatenates files, the newline between them lands in exactly the wrong place.
  • Comments and processing instructions are legal in the prolog, but only after the XML declaration.
  • The prolog ends where the root element's start tag begins. There is no marker for it.

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.