Export (0) Print
Expand All

Processing Instructions [XML Standards] 

Processing instructions can be used to pass information to applications in a way that escapes most XML rules. Processing instructions do not have to follow much internal syntax, can include markup characters without escaping them, and can appear anywhere in the document outside of other markup. They can appear in the prolog, including the document type definition (DTD), in textual content, or after the document. Their appearance is not noted by schema or DTD processors.

Processing instructions must begin with an identifier called a target, which follows rules similar to those for element and attribute names. Processing instruction targets are case-sensitive and must start with a letter or underscore. The rest of the target can contain letters, digits, hyphens, underscores, periods, and colons. Any valid XML textual characters can appear after the target.

NoteNote

The World Wide Web Consortium (W3C) Namespaces in XML recommendation suggests you avoid the use of colons in processing instruction names.

The following is the processing instruction syntax in the document map.

<?xml-stylesheet type="text/xsl" href="show_book.xsl"?>

Processing of the contents ends immediately after the string ?> is encountered.

Style Sheet Processing Instructions

In accordance with the W3C recommendation, Microsoft® Internet Explorer implements an xml-stylesheet processing instruction. This processing instruction must appear in the prolog, before the document or root element. Multiple processing instructions can appear, which can be useful with cascading style sheets, but most browsers use the first supported style sheet and ignore the rest.

The syntax for a style sheet processing instruction is as follows:

<?xml-stylesheet type="type" href="uri" ?>

where

NoteNote

type is text/css (to link to a cascading style sheet file) or text/xsl (to link to an XSLT file)

NoteNote

uri is the Uniform Resource Identifier (URI) of the style sheet. This URI is relative to the location of the XML document itself.

The following is an xml-stylesheet processing instruction identifying a style sheet built using a cascading style sheet.

<?xml-stylesheet href="/style.css" type="text/css" title="default stylesheet"?>

The following is an xml-stylesheet processing instruction identifying a style sheet built using Extensible Stylesheet Language (XSL).

<?xml-stylesheet href="/style.xsl" type="text/xsl" title="default stylesheet"?>

The following processing instruction is legal, but difficult for applications to process.

<?style – oh, try /style.css ?>

Many processing instructions use pseudo-attributes, content that looks like attributes and is easier for applications to process. The preceding example can be rendered using the W3C xml-stylesheet processing instruction:

<?xml-stylesheet href="/style.css" type="text/css" title="default stylesheet"?>

You can use processing instructions in the prolog to specify other document-wide processing, but you must write an application to support them.

NoteNote

Although the use of processing instructions is sometimes discouraged, their loose structure and the flexibility of their placement make them useful for sending messages to an application without disrupting the flow of XML information.

See Also

Concepts

Document Map

Show:
© 2014 Microsoft