How to join values in XPath?

To join text in XPath the concat() function can be used. This is useful when parsing HTML for data values that are distributed through multiple elements or attributes.

See this interactive example:

<!-- select all product details as one string --> <html> <div> <h2>Coffee</h2> <span data-currency="USD">4.69</span> </div> </html>

Note that concat() only works with strings so it'll automatically try convert elements to their text() values.

Question tagged: XPath

Related Posts

How to Parse XML

In this article, we'll explain about XML parsing. We'll start by defining XML files, their format and how to navigate them for data extraction.

Ultimate XPath Cheatsheet for HTML Parsing in Web Scraping

Ultimate companion for HTML parsing using XPath selectors. This cheatsheet contains all syntax explanations with interactive examples.

Web Scraping With Ruby

Introduction to web scraping with Ruby. How to handle http connections, parse html files for data, best practices, tips and an example project.