protected String buildXMLResultString(ResultSequence rs) throws Exception {
    DOMImplementationLS domLS =
        (DOMImplementationLS) domDoc.getImplementation().getFeature("LS", "3.0");
    LSOutput outputText = domLS.createLSOutput();
    LSSerializer serializer = domLS.createLSSerializer();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    outputText.setByteStream(outputStream);

    String actual = new String();
    Iterator iterator = rs.iterator();
    boolean queueSpace = false;
    while (iterator.hasNext()) {
      AnyType aat = (AnyType) iterator.next();
      if (aat instanceof NodeType) {
        NodeType nodeType = (NodeType) aat;
        Node node = nodeType.node_value();
        serializer.write(node, outputText);
        queueSpace = false;
      } else {
        if (queueSpace) outputText.getByteStream().write(32);
        outputText.getByteStream().write(aat.getStringValue().getBytes("UTF-8"));
        queueSpace = true;
      }
    }

    actual = outputStream.toString("UTF-8");
    actual = actual.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
    actual = actual.replace("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>", "");
    outputStream.close();
    return actual.trim();
  }
  /**
   * Node-Name operation.
   *
   * @param args Result from the expressions evaluation.
   * @throws DynamicError Dynamic error.
   * @return Result of fn:node-name operation.
   */
  public static ResultSequence node_name(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());

    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty()) return ResultBuffer.EMPTY;

    NodeType nt = (NodeType) arg1.first();

    QName nodename = nt.node_name();
    if (nodename == null) return ResultBuffer.EMPTY;

    return nodename;
  }