Java Utililty Methods XML Format

List of utility methods to do XML Format

Description

The list of methods to do XML Format are organized into topic(s).

Method

voidprintStream(InputStream is)
print Stream
StreamSource source = new StreamSource(is);
String msgString = null;
try {
    Transformer xFormer = TransformerFactory.newInstance().newTransformer();
    xFormer.setOutputProperty("omit-xml-declaration", "yes");
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    Result result = new StreamResult(outStream);
    xFormer.transform(source, result);
...
StringprintXML(Node node)
Transforms an XML to a String
TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer serializer;
try {
    serializer = tfactory.newTransformer();
    serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    StringWriter output = new StringWriter();
    serializer.transform(new DOMSource(node), new StreamResult(output));
...
StringxmlFormat(String xml)
xml Format
return xmlFormat(xml, 4);
StringxmlFormat(String xml)
xml Format
StringWriter writer;
try {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db;
    db = dbf.newDocumentBuilder();
    Document doc = db.parse(new InputSource(new StringReader(xml)));
    DOMSource source = new DOMSource(doc);
    writer = new StringWriter();
...