O'Reilly logo

XQuery by Priscilla Walmsley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Processing Instructions

Processing instructions are generally used in XML documents to tell the XML application to perform some particular action. For example, a processing instruction similar to:

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

appears in some XML documents to associate them with an XSLT stylesheet. When opened in some browsers, the XML document will be displayed using that stylesheet. This processing instruction has a target, which consists of the characters after the <?, up to the first space, namely xml-stylesheet. The rest of the characters are referred to as its content, namely type="text/xsl" href="formatter.xsl". Although the content of this particular processing instruction looks like a pair of attributes, it is simply considered a string.

Processing instructions can be both queried and constructed using XQuery.

Processing Instructions and the Data Model

Although processing instructions often appear at the beginning of an XML document, they can actually appear within element content or at the end of the document as well. Example 21-4 shows a small XML document with two processing instructions. The xml-stylesheet processing instruction appears on the second line, whereas doc-processor appears within the content of the b:header element. The first line is the XML declaration, which, although it looks like a processing instruction, is not considered to be one.

Example 21-4. XML document with processing instructions (pi.xml)

<?xml version="1.0" encoding="UTF-8"?> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required