The XPath language is designed to be embedded in another language (such as DOM API, XSLT, XQuery, ...) and cannot be used standalone. The original question does not specify what is the desired embedding.
Below is a very simple and short solution when XPath is embedded in XSLT.
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="div[@class='info']">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
when applied on this xml document:
<html>
<body>
<div class="info">
<h1>title1</h1> text1
<a href="somelink1">anchor1</a>
</div>
Something else here
<div class="info">
<h2>title2</h2> text2
<a href="somelink2">anchor2</a>
</div>
Something else here
<div class="info">
<h3>title3</h3> text3
<a href="somelink3">anchor3</a>
</div>
</body>
</html>
produces the wanted result:
<div class="info">
<h1>title1</h1> text1
<a href="somelink1">anchor1</a>
</div>
Something else here
<div class="info">
<h2>title2</h2> text2
<a href="somelink2">anchor2</a>
</div>
Something else here
<div class="info">
<h3>title3</h3> text3
<a href="somelink3">anchor3</a>
</div>