code: public static Serializer switchSerializerIfHTML(
            String ns, String localName, Properties props, Serializer oldSerializer)
              throws TransformerException
    {
      Serializer newSerializer = oldSerializer;
  
      if (((null == ns) || (ns.length() == 0))
              && localName.equalsIgnoreCase("html"))
      {
        // System.out.println("transformer.getOutputPropertyNoDefault(OutputKeys.METHOD): "+
        //              transformer.getOutputPropertyNoDefault(OutputKeys.METHOD));     
        // Access at level of hashtable to see if the method has been set.
        if (null != getOutputPropertyNoDefault(OutputKeys.METHOD, props))
          return newSerializer;
  
        // Getting the output properties this way won't cause a clone of 
        // the properties.
        Properties prevProperties = props;
        
        // We have to make sure we get an output properties with the proper 
        // defaults for the HTML method.  The easiest way to do this is to 
        // have the OutputProperties class do it.
        OutputProperties htmlOutputProperties = new OutputProperties(Method.HTML);
  
        htmlOutputProperties.copyFrom(prevProperties, true);
        Properties htmlProperties = htmlOutputProperties.getProperties();
  
  //      try
        {
          if (null != oldSerializer)
          {
            Serializer serializer =
              SerializerFactory.getSerializer(htmlProperties);
  
            Writer writer = oldSerializer.getWriter();
  
            if (null != writer)
              serializer.setWriter(writer);
            else
            {
              OutputStream os = serializer.getOutputStream();
  
              if (null != os)
                serializer.setOutputStream(os);
            }
            newSerializer = serializer;
          }
        }
  //      catch (java.io.IOException e)
  //      {
  //        throw new TransformerException(e);
  //      }
      }
      return newSerializer;
    }
docs: Switch to HTML serializer if element is HTML
  
  
  @param ns Namespace URI of the element
  @param localName Local part of name of element
  
  @throws TransformerException
  @return new contentHandler.