code: public void toWriter(boolean wholeDocument, Writer writer, Properties outputProperties)
          throws TransformerException {
              StreamResult streamResult = new StreamResult(writer);
  
              DOMSource domSource = null;
              if (wholeDocument) {
                  domSource = new DOMSource(getDocument());
              } else {
                  domSource = new DOMSource(getElement());
              }
  
              TransformerFactory tf = TransformerFactory.newInstance();
              Transformer serializer = tf.newTransformer();
  
              if (outputProperties != null) {
                  for (Entry<Object, Object> entry: outputProperties.entrySet()) {
                      serializer.setOutputProperty(
                          (String) entry.getKey(),
                          (String) entry.getValue());
                  }
              }
              serializer.transform(domSource, streamResult);
          }
docs: Serialize either the specific Element wrapped by this BaseXMLBuilder,
  or its entire XML document, to the given writer using the default
  {@link TransformerFactory} and {@link Transformer} classes.
  If output options are provided, these options are provided to the
  {@link Transformer} serializer.
  
  @param wholeDocument
  if true the whole XML document (i.e. the document root) is serialized,
  if false just the current Element and its descendants are serialized.
  @param writer
  a writer to which the serialized document is written.
  @param outputProperties
  settings for the {@link Transformer} serializer. This parameter may be
  null or an empty Properties object, in which case the default output
  properties will be applied.
  
  @throws TransformerException