code: public OutputStream getXpathResource(final String resourceName, final String xpath, final boolean nodeid,
          final Long revision, final OutputStream output, final boolean wrapResult) throws IOException,
          TTException {
  
          // work around because of query root char '/'
          String qQuery = xpath;
          if (xpath.charAt(0) == '/')
              qQuery = ".".concat(xpath);
          if (mDatabase.existsResource(resourceName)) {
              if (wrapResult) {
                  output.write(beginResult.getBytes());
                  doXPathRes(resourceName, revision, output, nodeid, qQuery);
                  output.write(endResult.getBytes());
              } else {
                  doXPathRes(resourceName, revision, output, nodeid, qQuery);
              }
  
          } else {
              throw new WebApplicationException(Response.Status.NOT_FOUND);
          }
          return output;
      }
docs: Getting part of the XML based on a XPath query
  
  @param resourceName
  where the content should be extracted
  @param xpath
  contains XPath query
  @param nodeid
  To response the resource with a restid for each node ( <code>true</code>) or without (
  <code>false</code>).
  @param revision
  The revision of the requested resource. If <code>null</code>,
  than response the latest revision.
  @param output
  The OutputStream reference which have to be modified and
  returned
  @return the queried XML fragment
  @throws IOException
  The exception occurred.
  @throws TTException