XPath Examples

This example shows how we can use XPath expressions in Java to query the DOM in server. Use the source code of this page loaded by your browser to query, in server all DOM nodes are created because itsnat:nocache=true is declared in the html root element (no node cached).

This document is HTML, unfortunately you can't use conventional expressions like "div" because in ItsNat HTML documents are ever managed as XHTML in server, so use instead ":div" (default prefix is empty) or the more verbose "*[name()='div']" to get the same results.


XPath Expression:

Examples:

//:div
//:div[1]
//:div/text()
//:div[:span='XPath Expression:']/:button/text()
//:input[@id="expressionId"]
//*[name() = 'h1' or not(name() = 'br')]
//*[namespace-uri() = 'http://www.w3.org/1999/xhtml']
/:html/:body/:h1

Result:



RETURN