Skip to main content

Search 400 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, guides, blog and product.

XPath operator

processing-instruction() node test

Selects processing instructions, optionally restricted to one target such as xml-stylesheet.

processing-instruction() selects every processing-instruction node on the axis. Supplying a string literal restricts the target, so processing-instruction('xml-stylesheet') ignores unrelated instructions.

The target is not an element name and the data after it is not parsed into attributes by XPath. The node's string-value is the raw instruction data.

Syntax
processing-instruction() or processing-instruction('target')
Returns
node-set
Kind
Operator
Version
XPath 1.0 (libxml2)

Worked examples

Each result below is what the evaluator returned, asserted on every test run. An empty result means an empty node-set — which is an answer, not an error.

  • count(/order/processing-instruction())on order.xmlRun
    1
  • count(/order/processing-instruction('audit'))on order.xmlRun
    1
  • normalize-space(string(/order/processing-instruction('audit')))on order.xmlRun
    retained

Run your own expression

What catches people out

  • The optional target must be a string literal, not a QName or wildcard.
  • Pseudo-attributes in instruction data are just text to XPath 1.0.
  • Like comments, processing instructions may be discarded by an upstream parser configuration.

The sample documents

Every example on this page runs against this document. The sitemap one is namespaced on purpose — almost every real XML document is, and that changes which expressions match.

order.xml
<?xml version="1.0" encoding="UTF-8"?>
<order id="A-1001" tier="gold">
  <customer country="NO">Ada Lovelace</customer>
  <!-- priority customer -->
  <?audit retained?>
  <lines>
    <line sku="WIDGET-1" qty="2"><price>14.50</price></line>
    <line sku="WIDGET-2" qty="1"><price>39.00</price></line>
    <line sku="GIFT-WRAP" qty="1"><price>0.00</price></line>
  </lines>
  <note>  Deliver after 09:00  </note>
</order>

Related

All 40 XPath entries

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.