What is the shortest way to pretty print a org.w3c.dom.Document to stdout?

前端 未结 6 1389
难免孤独
难免孤独 2020-11-27 11:08

What is the easiest way to pretty print (a.k.a. formatted) a org.w3c.dom.Document to stdout?

6条回答
  •  -上瘾入骨i
    2020-11-27 11:59

    How about:

    OutputFormat format = new OutputFormat(doc);
    format.setIndenting(true);
    XMLSerializer serializer = new XMLSerializer(System.out, format);
    serializer.serialize(doc);
    

提交回复
热议问题