X-Path
Overview
When standard tagging methods aren’t enough to isolate complex or deeply nested content, X-Path becomes a powerful tool. The X-Path feature in Milestone Schema Manager’s Advanced Configuration lets you define exact locations within the HTML of a page to extract specific data for schema tagging.
This guide will walk you through how to use X-Path to precisely target elements for schema tagging—especially helpful when basic tagging captures too much or too little information.
What Is X-Path and Why Use It?
X-Path (XML Path Language) is a query language used to select nodes from an HTML or XML document. In schema tagging, X-Path helps target:
- Specific spans, divs, or nested text
- Instances where CSS selectors alone don’t give clean results
- Cases where multiple elements share the same label or class, but only one is needed
Using X-Path ensures accuracy, precision, and reduced cleanup.
Step-by-Step: How to Use X-Path in the Schema Editor
Start Tagging the Schema Normally
Choose the schema type you need (e.g., Contact, Product, Event) and tag the property as you normally would. Click the three-dot menu (•••) next to the tagged property. Then select 'Advanced Configuration'.
Choose X-Path from the Filter Type
In the configuration panel:
- Click Add Filter
- From the dropdown, select X-Path
Enter the X-Path Expression
Type or paste your X-Path query into the field. This expression should point directly to the element containing your desired value.
Example: //div[@class='contact-info']/span[2]
This targets the second <span> within a div tagged contact-info.
Preview the Output
As soon as the X-Path is entered, the Schema Manager will fetch and display the value based on your query.
If the value looks correct, click Save.
Complete Validation and Publish
After saving, proceed with Save & Generate to validate your schema instance. If successful, your X-Path-filtered value will be published as part of the schema.
Glossary of Terms
Term | Definition |
---|---|
X-Path | A language used to locate and extract specific elements in HTML or XML documents. |
Advanced Configuration | A schema editor setting that allows custom logic like filters or X-Path expressions. |
Add Filter | An option in the editor used to refine what content is tagged. |
X-Path Expression | A query that defines a path to an element or text within the HTML structure. |
Schema Property | A specific element within a schema type (e.g., name, telephone, price). |
Tips for Success
- Test Your X-Path in a Browser First
Use Chrome DevTools or a browser-based X-Path tester to validate your path before applying it in Schema Manager.
- Target Unique Elements
Try to use unique classes or attributes in your X-Path to avoid capturing the wrong element.
- Avoid Overly Generic Paths
Generic queries like //span[1] may result in unintended tagging. Be specific to prevent errors.
- Use X-Path When Other Filters Fail
X-Path is especially useful when:
- Standard text filters don’t isolate the value
- The structure of the content is inconsistent
- There are multiple identical tags on a page