try { XPathQueryServiceImpl service= (XPathQueryServiceImpl) collection .getService("XPathQueryService", "1.0"); service.setProperty(OutputKeys.INDENT, properties .getProperty("indent")); ResourceSet result= service.query(xpath); XMLResource resource; int howmany= count.getNumber().intValue(); int j= 0; StringBuffer contents = new StringBuffer(); for (ResourceIterator i = result.getIterator(); i.hasMoreResources() && j < howmany; j++) { resource= (XMLResource) i.nextResource(); try { contents.append((String) resource.getContent()); contents.append("\n"); } catch (XMLDBException e) { ClientFrame.showErrorMessage( "An error occurred while retrieving results: " + e.getMessage()                        , e); } } resultDisplay.setText(contents.toString()); resultDisplay.setCaretPosition(0); resultDisplay.scrollToCaret(); } catch (XMLDBException e) { ClientFrame.showErrorMessage( "An exception occurred during query execution: " + e.getMessage()					, e); } if(client.queryHistory.isEmpty() || !((String)client.queryHistory.getLast()).equals(xpath)) { client.addToHistory(xpath); if(xpath.length() > 40) xpath = xpath.substring(0, 40); history.addElement(xpath); }
new QueryThread(xpath).start();
	private void doQuery() {		String xpath= (String) query.getText();		if (xpath.length() == 0)			return;		resultDisplay.setText("");		try {			XPathQueryServiceImpl service= (XPathQueryServiceImpl) collection					.getService("XPathQueryService", "1.0");			service.setProperty(OutputKeys.INDENT, properties					.getProperty("indent"));			ResourceSet result= service.query(xpath);            XMLResource resource;            int howmany= count.getNumber().intValue();            int j= 0;            StringBuffer contents = new StringBuffer();            for (ResourceIterator i = result.getIterator(); i.hasMoreResources() && j < howmany; j++) {                resource= (XMLResource) i.nextResource();                try {                    contents.append((String) resource.getContent());                    contents.append("\n");                } catch (XMLDBException e) {                    ClientFrame.showErrorMessage(                            "An error occurred while retrieving results: "                            + e.getMessage()                        , e);                }            }            resultDisplay.setText(contents.toString());            resultDisplay.setCaretPosition(0);            resultDisplay.scrollToCaret();		} catch (XMLDBException e) {			ClientFrame.showErrorMessage(					"An exception occurred during query execution: "							+ e.getMessage()					, e);		}		if(client.queryHistory.isEmpty() || !((String)client.queryHistory.getLast()).equals(xpath)) {			client.addToHistory(xpath);			if(xpath.length() > 40)				xpath = xpath.substring(0, 40);			history.addElement(xpath);		}	}