Home › Developer Tools › XPath Tester

XPath Tester

Paste an XML or HTML document, type an XPath expression and instantly see which nodes match, highlighted in the document and listed with their full paths and values. Numbers, strings and booleans from functions like count() are shown too. Everything runs locally with your browser's XPath engine.

Last updated:

Matches highlighted

    

Results

    Runs the browser's built-in XPath 1.0 engine on your own device; nothing is uploaded. Tip: click a result to jump to it in the document.

    Advertisement
    Advertisement

    How to use the XPath Tester

    1. Paste your document into the Document box or open a file, and choose Parse as XML or Parse as HTML. A sample is loaded to start with.
    2. Type an XPath expression in the box at the top, or click an example chip to try one.
    3. Read the summary: how many nodes matched, or the number, string or boolean result of a function.
    4. Check the highlights in the formatted document on the right and the result list below; click a result to jump to it.
    5. Copy the values, markup or XPath paths of all matches for use in your code or scraper.

    XPath cheat sheet

    ExpressionSelects
    /library/bookbook children of the root element library
    //bookall book elements anywhere in the document
    //book/@idthe id attribute of every book
    //book[1]each book that is the first book child of its parent
    (//book)[1]the first book in the whole document
    //book[last()]the last book of each parent
    //book[@lang='fr']books whose lang attribute equals fr
    //book[price > 30]books with a price child greater than 30
    //book[not(@available)]books without an available attribute
    //title/text()the text nodes inside title elements
    //*[not(*)]leaf elements (no child elements)
    //book | //magazineunion of both node sets

    Axes

    AxisShort formMeaning
    child::titledirect children (the default axis)
    descendant-or-self::node()///the node and everything below it
    attribute::@attributes
    parent::node()..the parent
    self::node().the current node
    ancestor::-parent, grandparent and up to the root
    following-sibling:: / preceding-sibling::-siblings after / before the node
    following:: / preceding::-all nodes after / before it in document order

    XPath 1.0 functions

    GroupFunctions
    Node setslast(), position(), count(), name(), local-name(), namespace-uri(), id()
    Stringsstring(), concat(), contains(), starts-with(), substring(), substring-before(), substring-after(), string-length(), normalize-space(), translate()
    Numbersnumber(), sum(), floor(), ceiling(), round()
    Booleansboolean(), not(), true(), false(), lang()

    Case-insensitive match in XPath 1.0: //title[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'xpath')]. Match a CSS class among several: //li[contains(concat(' ', normalize-space(@class), ' '), ' sale ')].

    Frequently asked questions

    What is XPath?

    XPath (XML Path Language) is a W3C query language for selecting parts of an XML or HTML document. An expression like //book[price > 30]/title walks the document tree and returns matching nodes, or computes a value with functions such as count() and sum(). It is used in XSLT, Selenium and Playwright locators, web scrapers, and XML libraries in nearly every programming language.

    Which XPath version does this tester use?

    It uses the XPath 1.0 engine built into your browser (document.evaluate), the same version supported by browsers, Selenium, lxml, libxml2, Python's ElementTree subset and Java's default javax.xml.xpath. XPath 2.0 and 3.1 functions such as lower-case(), ends-with(), matches() or max() are not available; use translate(), contains(), starts-with() and substring() instead.

    Why does my XPath return nothing on XML with xmlns?

    When the root element declares a default namespace (xmlns="…"), every unprefixed element belongs to that namespace and a plain //item does not match it in XPath 1.0. This tool ignores the default namespace by default so plain names work. Untick that option to use the prefix d: instead, for example //d:item. Prefixes declared in the document, like atom: or soap:, are resolved automatically.

    What is the difference between / and // in XPath?

    A single slash selects direct children: /library/book returns book elements that are children of the root library element. A double slash selects descendants at any depth: //book returns every book element anywhere in the document, and //book//title every title inside a book, however deeply nested.

    How do I select an element by attribute or text?

    Use a predicate in square brackets. //book[@id='b2'] selects by attribute value, //book[title='Mastering XPath'] by child text, //a[contains(@href, 'example')] by part of an attribute, and //p[contains(., 'Contact')] by text anywhere inside the element. Use normalize-space() to ignore extra whitespace.

    Is HTML handled differently from XML?

    Yes. In HTML mode the page is parsed like a browser would, so unclosed tags are fixed and missing html, head, body and tbody elements are added automatically. Remember the added tbody when you copy an XPath from table markup: //table//tr is safer than //table/tr. Tag names are matched in lowercase.

    Is my document uploaded?

    No. Parsing and XPath evaluation happen in JavaScript inside this page, so your XML or HTML never leaves your device.

    Are all the tools on FreeToolCabin tested for quality and accuracy?

    Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

    Related tools

    JSONPath TesterTest JSONPath expressions live: filters, slices, wildcards and recursive search, with matches highlighted.XML FormatterBeautify, validate and minify XML with a collapsible tree view.Regex TesterTest and debug regular expressions live.XML to JSONConvert XML to JSON with validation.Online Python CompilerRun Python 3 in your browser with input(), numpy, pandas, charts and share links.JSON EditorEdit JSON in a tree and as code side by side: add, rename, drag, change types, undo and download.Unzip FilesOpen and extract ZIP files online.RAR & 7z ExtractorOpen RAR, 7z and other archives online and extract files.File Info ViewerCheck file size, type, date and MD5/SHA hashes.SQLite ViewerOpen .db and .sqlite files in your browser, browse tables and run SQL queries.DOCX ViewerOpen and read Word .docx files in your browser, then print or save them as HTML.EPUB ReaderOpen and read EPUB e-books in your browser with pages, a table of contents and font controls.What Is My BrowserSee your browser, version, OS, engine, screen and which web features it supports.Font ViewerPreview TTF, OTF, WOFF and WOFF2 fonts with sample text, waterfall, glyphs and metadata.Markdown EditorWrite Markdown with a toolbar, live split preview, autosave and .md or HTML export.Regex Cheat Sheet75+ ready-to-use regex patterns for emails, URLs, IPs and dates, each with a live test box.JavaScript Keycode FinderPress any key to see its JavaScript key, code, keyCode, which, location and modifiers.QR Code ScannerScan QR codes with your camera or from an image and safely read the link or text.RAID CalculatorUsable capacity, efficiency and fault tolerance for RAID 0, 1, 5, 6, 10, 50 and 60 arrays.Mermaid Diagram EditorWrite Mermaid code and see flowcharts, sequence, Gantt and ER diagrams live. Export SVG or PNG.Country Codes ListSearch ISO 3166 alpha-2, alpha-3 and numeric country codes with calling codes and TLDs.CSS Selector TesterTest CSS selectors on your HTML: highlighted matches, match count and specificity.Git Cheat SheetSearchable Git command reference by task, with copy buttons and an undo/rename/fix wizard.HAR File ViewerOpen a .har file to see a waterfall timeline, headers, bodies, timings and size totals.jq PlaygroundRun jq filters on JSON in your browser with live output, flags and an example library.Markdown Cheat SheetInteractive Markdown syntax reference: edit every example and see the live rendered preview.Regex ExplainerPaste a regular expression and get a plain-English breakdown, railroad diagram and flag notes.EML File ViewerOpen .eml email files to read the message, headers and raw source and save attachments.Graphviz Online ViewerWrite Graphviz DOT code and render graphs live; switch layout engines, export SVG or PNG.JavaScript Online CompilerWrite and run JavaScript in your browser with a console, timing, error lines and share links.Jupyter Notebook ViewerOpen .ipynb files and read code, Markdown, math, tables, plots and errors without Python.LaTeX Table GeneratorEdit a table like a spreadsheet or paste from Excel and get LaTeX tabular or booktabs code.Log File ViewerOpen huge log files with level colors, regex and time filters, JSON pretty-print and tail -f.Logic Gate SimulatorBuild logic circuits with AND, OR, NOT, XOR gates and flip-flops; see live outputs and truth tables.MSG File ViewerOpen Outlook .msg emails in your browser: sender, recipients, body, headers and attachments.Online Code EditorVS Code-style editor in your browser: tabs, 50+ languages, find/replace, autosave.Online Hex EditorOpen any file as hex and ASCII, edit bytes, search, inspect values and save the result.PHP Online CompilerRun PHP 8 code in your browser with output, HTML preview, error lines and share links.Folder Compare ToolCompare two folders by file list, size and SHA-256 hash, then open a text diff of changed files.Glob Pattern TesterTest glob patterns like **/*.js, {a,b} and !exclusions against a list of file paths.JMESPath TesterEvaluate JMESPath expressions against JSON live, the query language used by the AWS CLI.MongoDB Query TesterTest MongoDB find filters, projections and aggregation pipelines on sample JSON documents.Semantic Version CalculatorBump, compare, sort and test SemVer versions against npm ^, ~ and x ranges.XSLT TesterRun an XSLT 1.0 stylesheet on XML in your browser and see the output as HTML, XML or text.ASCII Diagram EditorDraw boxes, arrows and text on a character grid and copy plain-text diagrams for code and READMEs.DBF File ViewerOpen dBase .dbf files and shapefile tables, search and sort records, export CSV or XLSX.MBOX File ViewerOpen .mbox mail archives: list and search messages, read them, save attachments, export EML.MDB File ViewerOpen Access .mdb and .accdb databases in your browser: list tables, view rows, export CSV.Shapefile ViewerView zipped shapefiles on a map with the attribute table, then export to GeoJSON or CSV.PlantUML EditorWrite PlantUML and see sequence, class, activity and more diagrams live. Export SVG or PNG.Sorting Algorithm VisualizerWatch bubble, insertion, merge, quick, heap and radix sort step by step with live counters.Lottie ViewerOpen Lottie JSON or .lottie files to play, pause, scrub frames, change speed and see details.Diff ViewerPaste a git diff or .patch file and view it side by side or inline, with file navigation.EditorConfig GeneratorBuild an .editorconfig with indent, charset, line endings and trim rules per file pattern.
    See all 53 Code Playgrounds & Testers →