Here you can find the source of writeXHTML(Document htmldoc, OutputStream out)
Parameter | Description |
---|---|
htmldoc | Document to output |
out | Stream to write to |
Parameter | Description |
---|---|
IOException | thrown on IO errors |
public static void writeXHTML(Document htmldoc, OutputStream out) throws IOException
//package com.java2s; /*/*w w w . j av a 2s . c om*/ This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures Copyright (C) 2016 Ludwig-Maximilians-Universit?t M?nchen Lehr- und Forschungseinheit f?r Datenbanksysteme ELKI Development Team This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.IOException; import java.io.OutputStream; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; public class Main { /** * XHTML PUBLIC doctype */ public static final String HTML_XHTML_TRANSITIONAL_DOCTYPE_PUBLIC = "-//W3C//DTD XHTML 1.0 Transitional//EN"; /** * XHTML SYSTEM doctype */ public static final String HTML_XHTML_TRANSITIONAL_DOCTYPE_SYSTEM = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"; /** * Write an HTML document to an output stream. * * @param htmldoc Document to output * @param out Stream to write to * @throws IOException thrown on IO errors */ public static void writeXHTML(Document htmldoc, OutputStream out) throws IOException { javax.xml.transform.Result result = new StreamResult(out); // Use a transformer for pretty printing Transformer xformer; try { xformer = TransformerFactory.newInstance().newTransformer(); xformer.setOutputProperty(OutputKeys.INDENT, "yes"); // TODO: ensure the "meta" tag doesn't claim a different encoding! xformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); xformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, HTML_XHTML_TRANSITIONAL_DOCTYPE_PUBLIC); xformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, HTML_XHTML_TRANSITIONAL_DOCTYPE_SYSTEM); xformer.transform(new DOMSource(htmldoc), result); } catch (TransformerException e1) { throw new IOException(e1); } out.flush(); } }