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

Processing instruction

A <?target data?> node carrying instructions for an application, passed through the parser without being interpreted as content.

A processing instruction has a target — an NCName saying which application should care — and everything up to the closing ?> is opaque data for that application. The parser guarantees only that the syntax is well-formed; it attaches no meaning at all.

The best-known one is xml-stylesheet, which associates an XSLT or CSS stylesheet with a document and is why a raw RSS feed sometimes renders as a styled page in a browser. Targets beginning with the letters xml, in any case, are reserved.

Defined in
XML 1.0 §2.6
Category
Document syntax
Also written
PI, <?target data?>

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.

  • Processing instructions before the root element are still nodes in the tree.

    document.xml
    <?xml-stylesheet href="feed.xsl" type="text/xsl"?>
    <x><?sort by="name"?></x>
    expression
    count(//processing-instruction())

    What the engine returns

    2
  • Their data is opaque: it is not parsed into attributes.

    document.xml
    <?xml-stylesheet href="feed.xsl" type="text/xsl"?>
    <x/>
    expression
    string(//processing-instruction()[1])

    What the engine returns

    href="feed.xsl" type="text/xsl"

What catches people out

  • The XML declaration looks like a PI but is not one, and processing-instruction() will not select it.
  • Targets starting with "xml" in any case are reserved by the specification.
  • A PI's data may not contain ?>, and there is no escape 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.