| 7474 |
vikram.rag |
1 |
package com.amazonservices.mws.products.model;
|
|
|
2 |
|
|
|
3 |
import java.io.StringWriter;
|
|
|
4 |
|
|
|
5 |
import javax.xml.transform.OutputKeys;
|
|
|
6 |
import javax.xml.transform.Transformer;
|
|
|
7 |
import javax.xml.transform.TransformerException;
|
|
|
8 |
import javax.xml.transform.TransformerFactory;
|
|
|
9 |
import javax.xml.transform.dom.DOMSource;
|
|
|
10 |
import javax.xml.transform.stream.StreamResult;
|
|
|
11 |
|
|
|
12 |
import org.w3c.dom.Node;
|
|
|
13 |
|
|
|
14 |
public class ProductsUtil {
|
|
|
15 |
|
|
|
16 |
public static String formatXml(Node node) {
|
|
|
17 |
try {
|
|
|
18 |
// Set up the output transformer
|
|
|
19 |
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
|
|
20 |
Transformer transformer = transformerFactory.newTransformer();
|
|
|
21 |
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
|
|
|
22 |
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
|
|
|
23 |
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
|
|
24 |
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
|
|
|
25 |
|
|
|
26 |
// Print the DOM node
|
|
|
27 |
StringWriter sw = new StringWriter();
|
|
|
28 |
StreamResult result = new StreamResult(sw);
|
|
|
29 |
DOMSource source = new DOMSource(node);
|
|
|
30 |
transformer.transform(source, result);
|
|
|
31 |
return sw.toString();
|
|
|
32 |
} catch (TransformerException e) {
|
|
|
33 |
throw new RuntimeException(e);
|
|
|
34 |
}
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
}
|