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

Comment

A <!-- … --> block that carries no document content and is not part of any element's text.

Comments may appear anywhere outside markup — in the prolog, between elements, after the root — but never inside a tag. They are nodes in the data model: XPath selects them with comment(), and a canonicalizer keeps or drops them depending on the mode.

The one syntactic surprise is that -- cannot appear inside a comment. The rule is inherited from SGML, it catches people who draw separator lines out of hyphens, and it is fatal rather than a warning.

Defined in
XML 1.0 §2.5
Category
Document syntax
Also written
<!-- -->

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 comment is not text: it does not appear in the element's string value.

    document.xml
    <x>a<!-- hidden -->b</x>
    expression
    string(/x)

    What the engine returns

    ab
  • But it does split the text around it into two nodes.

    document.xml
    <x>a<!-- hidden -->b</x>
    expression
    count(/x/text())

    What the engine returns

    2

What catches people out

  • -- is illegal inside a comment, so <!-- ---- --> will not parse.
  • A comment cannot end in a hyphen: <!-- like this ---> contains -- before the close.
  • Comments are nodes. Code that treats an element's first child as its text will trip over one.

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.