try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse( new Inputsource( "test.xml")); XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); String result = xpath.evaluate( /contacts/contact/name/first[text()="Edwin"], document.getDocumentElement()); } catch ( Exception e) { e.printStacktrace(); }