XPath Search in Pages

This is an advanced built-in script. Use XPath Search in Pages to search each page’s source using the provided XPath expression.

XPath Search in Pages is more powerful than the built-in Confluence search, especially when it comes to identifying hidden structural problems in your content. But that power comes at the cost of speed and efficiency. It is best only to run this built-in script on a single space. It takes about 1.5 seconds to search a space with 2,500 pages.

To use XPath Search in Pages, you should be reasonably familiar with the Confluence XHTML storage format, and/or be prepared to examine a page’s source with the Confluence Source Editor in order to work out what expression you need.

Run the script

Follow these steps to run the built-in script:

  1. Navigate to General Configuration > ScriptRunner > Built-In Scripts.
  2. Select XPath Search in Pages.
  3. Enter a CQL Query to select the content you want to work with. 

    • CQL autocomplete is available for this field. Start typing to see possible CQL statements.
    • For help with CQL, visit CQL Guide
    • Select Show Examples to see examples of CQL statements.
  4. Enter the expression in Xpath Query.
    Select Show Examples for common expressions to use with this built-in script.

  5. Select Run.

Results

Once you run the script, the results appear.

Example

Search for pages with images in a certain space

You could use this script if you require a high degree of control over the presentation of your wiki pages, and you want to make sure everything is correct. You could run the following script to see all pages with images: 

  1. Navigate to General Configuration > ScriptRunner > Built-In Scripts.
  2. Select XPath Search in Pages.
  3. For CQL Query, enter type = page AND space = DS to select all of the pages in the Demonstration Space.  
  4. Enter //ac:image or select Pages with images from Show Examples for the Xpath Query
  5. Select Run

Results

The script returns the pages with images in the Demonstration Space. Each page appears as a link. 


On this page