> ## Documentation Index
> Fetch the complete documentation index at: https://docs.permutive.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Using XPath Selectors

> How to scope content classifications to the article body with an XPath selector

## Overview

An XPath is an expression that points at part of a page. Classification providers that accept one read only the matching part of the page instead of the whole document, so navigation, adverts, recommended articles, comments and legal boilerplate do not influence the classification.

<Info>
  **Prerequisites:**

  * Access to the Permutive Dashboard
  * A classification provider that supports XPath selectors — its configuration shows a **Set XPath** field. IBM Watson and Permutive Brand Safety both do
</Info>

## Why Set an XPath

Most article pages carry far more text than the article itself. A page about a cycling race that also lists ten recommended stories about politics can come back classified as politics, because the classifier sees all of it.

Pointing the provider at the element that wraps the article body removes that noise. It usually improves the categories you get back, and on providers billed by content volume it reduces the amount of text sent for classification.

## Where XPaths Are Configured

| Where                                                                      | What it applies to                                                                                                    |
| :------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------- |
| **Provider configuration** — *Contextual > Catalog > provider > Set XPath* | Production classifications. Configured per domain, so sites with different templates can each have their own selector |
| **Preview** — *Advanced settings > XPath*                                  | A single preview run. Use it to try a selector before saving it                                                       |

## Finding an XPath

<Steps>
  <Step title="Open a typical article">
    Pick a page that represents the template you want to classify, not an unusual one.
  </Step>

  <Step title="Inspect the article body">
    Right-click a paragraph in the middle of the article and choose *Inspect* to open your browser's developer tools.
  </Step>

  <Step title="Walk up to the wrapping element">
    In the elements panel, move up the tree until the highlighted region covers the article and nothing else. Stop before it starts including the header, sidebar or footer.
  </Step>

  <Step title="Copy the XPath">
    Right-click that element and choose *Copy > Copy XPath*.
  </Step>

  <Step title="Generalise it">
    The copied expression is an absolute path such as `/html/body/div[3]/div[2]/main/article`, which breaks as soon as the page structure changes. Shorten it to something that describes the element instead — `//article`, `//main`, or `//div[@class="article-body"]`.
  </Step>
</Steps>

<Tip>
  **Try the obvious ones first**: many sites are marked up with a single `article` or `main` element around the story. Test `//article` and then `//main` before writing anything bespoke.
</Tip>

## Checking a Selector

<Steps>
  <Step title="Open the preview">
    Navigate to *Contextual > Catalog*, hover over the provider tile and click *Preview*.
  </Step>

  <Step title="Enter a URL and expand Advanced settings">
    Enter an article URL from your site, then expand *Advanced settings* and paste the XPath.
  </Step>

  <Step title="Classify">
    Click *Classify* and review the results.
  </Step>

  <Step title="Compare">
    Clear the XPath and classify the same URL again. The difference tells you whether the selector is helping.
  </Step>
</Steps>

Try the selector on several pages from the same template before saving it, and repeat the exercise for each domain you configure.

<Warning>
  **A selector that matches nothing stops the classification.** If the element never appears on the page, the preview reports that the selector was not found and, in production, the page is not classified at all. IBM Watson is the exception: it reissues the request without the XPath, so the page is classified from the full document instead.
</Warning>

<Note>
  **Only the first match is read.** If an expression matches several elements, the provider classifies the first one and ignores the rest. A broad selector such as `//div` will quietly classify one fragment of the page. Prefer an expression that resolves to exactly one element.
</Note>

## Next Steps

<CardGroup cols={2}>
  <Card title="Previewing Classifications" icon="eye" href="/guides/signals/cohorts/contextual/previewing-classifications">
    Test how providers classify your content
  </Card>

  <Card title="Enabling Classification Providers" icon="toggle-on" href="/guides/signals/cohorts/contextual/enabling-classification-providers">
    Enable and configure NLP classification providers
  </Card>
</CardGroup>
