Defining a XPath is helpful when you can’t identify a URL pattern for your page template.


Training Objectives: Learn how to use XPaths to isolate patterns in your XML code so that you can tell the Highlighter where to deploy the code.


What is an XPath?

An XPath basically provides users with a flexible way of addressing or pointing to different parts of an XML document.


How we use XPaths?

We use XPaths to try to find a commonality across similar pages in a page template (that is unique to that page template), so that we can tell the Highlighter where to apply the markup.


XPaths can direct the Schema App Highlighter to apply specific markup to:


  • A particular part of an XML document
  • Content on a page that includes a specific attribute (or does not include a specific attribute)
  • Content on a page that includes a combination of attributes, etc.

Defining an XPath can get a little tricky, so please reach out to your Schema App CSM if you run into challenges.


Finding an XPath unique to your page template


Use Case #1:  We want to mark up a product page but there isn’t a unique URL pattern for products. We’ve discovered that model # is something unique to products that could be used to identify product pages.


Use Case #2:  We want to mark up a blog page but there isn’t a unique URL pattern for blogs. We’ve discovered that author is something unique to blogs that could be used to identify those pages.


Process:


  1. Find the code on your website that you wish the augment with schema markup:
    • Using your browser, choose the section on your page that you want to find the code for. You can inspect the code within the Schema App Highlighter, but we don’t recommend doing so because it may deliver results that don’t match those on your website.
    • Right click on the element and choose “Inspect” (the console will pop up in the Highlighter)
    • Search for the code using key command “Ctrl+F”
  2. Right click “Copy” > ” Copy XPath”



? We recommend downloading the Chrome extension – XPath Helper, to find XPaths easily for all content (except sub-templates). The XPath helper makes it easy to extract, edit, and evaluate XPath queries on any webpage.


Test the XPath


  1. Using your browser, open a new window and navigate to a different page that uses the same page template.
  2. Use the “XPath Helper”, and paste the XPath into the query box.
    • If the query produces a result showing the same element you had copied the xPath of, you’ll know that the XPath works for that particular page
    • If the query returns a different result from the element expected, reach out to your Customer Success Manager and they will be able to assist you in modifying the xPath to be reliable.
  3. As a final step, we recommend testing the xPath with the xPath Helper on pages where you would not expect the element to match. This can help to confirm that the element being used is in fact unique to the pageset you are seeking to define.