Here you can find the source of dumpDoc(Document domTree, PrintStream out)
Parameter | Description |
---|---|
domTree | a parameter |
out | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static void dumpDoc(Document domTree, PrintStream out) throws Exception
//package com.java2s; /*//w w w. j a va2 s . c o m * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ import java.io.PrintStream; import java.io.StringWriter; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; 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 { /** * @param domTree * @param out * @throws Exception */ public static void dumpDoc(Document domTree, PrintStream out) throws Exception { TransformerFactory transformerFact = TransformerFactory .newInstance(); transformerFact.setAttribute("indent-number", 4); Transformer transformer = transformerFact.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //initialize StreamResult with File object to save to file StreamResult result = new StreamResult(new StringWriter()); DOMSource source = new DOMSource(domTree); transformer.transform(source, result); String xmlString = result.getWriter().toString(); out.println(xmlString); } }