code: public void save(Writer writer, boolean header, boolean flush) throws IOException {
          final PrintWriter out = new PrintWriter(new BufferedWriter(writer));
          try {
              if (header) {
                  out.println("<?xml version='1.0' encoding='UTF-8'?>");
              }
              toStringRep("", new XAppender() {
                  @Override
                  public XAppender append(Object o) {
                      out.print(o);
                      return this;
                  }
              });
          } finally {
              if (flush) {
                  out.flush();
              }
          }
      }
docs: Save this XML into the supplied output writer.
  @param writer the output writer
  @param header write the XML processing instruction as well?
  @throws IOException on error