XML Processing Instruction Syntax and Usage

An XML processing instruction (PI) allows document authors to embed application-specific instructions directly within an XML document. This article explains the standard syntax for defining an XML processing instruction, details the rules governing its target and data components, and provides practical examples of proper usage in well-formed XML.

Standard Syntax Structure

An XML processing instruction begins with the delimiter <? and ends with the delimiter ?>. The basic structure follows this format:

<?target data?>

The component directly following the opening delimiter is the target, followed by at least one whitespace character, and then the optional data (or instruction content).

Syntax Rules for the Target

The target, formally known as the PITarget, identifies the application or process for which the instruction is intended. It must adhere to the following rules:

Syntax Rules for the Data

The data component contains the parameters or code sent to the processing application:

Common Examples

XML Stylesheet Association

A standard use case for processing instructions is linking a stylesheet to an XML document:

<?xml-stylesheet type="text/css" href="styles.css"?>

Custom Application Directives

Custom applications can read bespoke instructions to modify how a document is rendered, exported, or transformed:

<?render-engine page-break="true" orientation="landscape"?>

Instruction Without Data

<?clear-cache?>