XPath Tester: Node Types, Axes and Predicate Filters

Open Tool XPath Online Tester

XPath is a path and a node selection

XPath treats a document as a tree and selects node sets by walking from a context node. Absolute paths start at the root with a single slash; a double slash means any depth; brackets hold predicates filtering by position or condition. Evaluation uses the browser's native engine, so syntax must follow XPath 1.0 and results distinguish element, attribute and text nodes — //book returns elements while //book/title/text() returns the text itself.

Steps

  1. Paste XML or HTML source on the left.
  2. Type a path or pick a preset such as wildcard, title text, any element with an id, first book, or all text nodes.
  3. Tick whitespace-only text node skipping to avoid indentation noise.
  4. Query to see matched nodes, their types and full paths.
  5. Copy or download results, or clear.

Three predicate styles

By position: book[1] takes the first because XPath indexing starts at one, and book[last()] takes the last. By attribute: //book[@id='b1'] matches a value while //*[@id] matches presence. By content: numeric comparisons such as //book[price>10] and string functions such as contains. Predicates stack, so //book[@lang='en'][price<10] requires both.

Axes and text nodes

Axes set direction: child, descendant, parent, ancestor, following-sibling and preceding-sibling among others. Writing //title/following-sibling::price survives irregular markup better than fixed depth. Text comes via text(), attributes via the at sign, comments via comment(). Browsers generally handle namespace prefixes poorly, so documents with xmlns need a check before matching.

Common mistakes

Counting from zero never matches, since XPath is one-based. Mixing single and double slashes changes meaning: a direct child versus any depth. Writing a child element name where an attribute is meant breaks matching. Feeding HTML as strict XML fails because the parsed tree differs from source. Comparing strings gives lexicographic order, where ten sorts below nine, so numeric predicates need conversion. And default namespaces can make prefix-free paths match nothing at all.

When XPath is the right tool:It shines for structured extraction, XML configuration lookups and legacy interface parsing, because it expresses position, parentage and attribute equality. CSS selectors are terser for scraping but cannot climb to a parent or filter by text content, where XPath wins. Namespaced SOAP responses need a dedicated parser either way. In bulk scraping, keep paths tight — a bare wildcard scans the whole tree and costs real time.

⏫︎