code: public void save(Writer stream) throws IOException {
          final PrintWriter out = new PrintWriter(new BufferedWriter(stream));
          try {
              out.println("<?xml version='1.0' encoding='UTF-8'?>");
              toStringRep("", new HashMap<String, String>(), new XNAppender() {
                  @Override
                  public XNAppender append(Object o) {
                      out.print(o);
                      return this;
                  }
                  @Override
                  public int length() {
                      return 0; // Not used here
                  }
              }, null);
          } finally {
              out.flush();
          }
      }
docs: Save this XML into the given writer.
  Does not close the writer.
  @param stream the output writer
  @throws IOException on error