SORU
24 ŞUBAT 2010, ÇARŞAMBA


java: en kısa yol için epey bir baskı org stdout.w3c.dom.Belge

Oldukça yazdırmak için en kolay yolu nedir.k.bir. biçimlendirilmiş) 1* *stdout?

CEVAP
24 ŞUBAT 2010, ÇARŞAMBA


Dediğimiz yöntem bu gibi görünüyor nerede printDocument(doc, System.out),:

public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException {
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer = tf.newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

    transformer.transform(new DOMSource(doc), 
         new StreamResult(new OutputStreamWriter(out, "UTF-8")));
}

(indent-amount isteğe bağlıdır ve belirli bir yapılandırma) ile çalışmayabilir

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Film Riot

    Film Riot

    16 NİSAN 2006
  • Living Waters

    Living Water

    9 AĞUSTOS 2006
  • Visual Life

    Visual Life

    3 Temmuz 2006