Can I use XPath selectors in Cheerio?

No, you can not use XPath selectors in Cheerio. According to these GitHub issues, there is no plan to support XPaths in Cheerio.

GitHub Issue

However, if you simply want to work with XML documents and parse those using Cheerio, it is possible. Here is some sample code for parsing XML using Cheerio.

const cheerio = require('cheerio');
const xml = `
    <book category="web">
      <title lang="en">Practical Python Projects</title>
      <author>Yasoob Khalid</author>
    <book category="web">
      <title lang="en">Intermediate Python</title>
      <author>Yasoob Khalid</author>

// Load the XML document as a Cheerio object
const $ = cheerio.load(xml, { xml: true });

// Select all book titles 
const titles = $('book > title');

// Print the text content of each title
titles.each((i, title) => {

// Output:
// Practical Python Projects
// Intermediate Python

Related Cheerio web scraping questions: