Example usage for javax.xml.transform TransformerConfigurationException getClass

List of usage examples for javax.xml.transform TransformerConfigurationException getClass

Introduction

In this page you can find the example usage for javax.xml.transform TransformerConfigurationException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:Main.java

public static String XMLDocumentToString(Document _doc) {
    TransformerFactory transfac = TransformerFactory.newInstance();
    Transformer trans;/*from w  w w .  jav a2s  .  co  m*/
    String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    try {
        trans = transfac.newTransformer();

        trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        trans.setOutputProperty(OutputKeys.INDENT, "yes");
        StringWriter sw = new StringWriter();
        StreamResult result = new StreamResult(sw);
        DOMSource source = new DOMSource(_doc);
        trans.transform(source, result);
        xmlString += sw.toString();
    } catch (TransformerConfigurationException e) {
        System.out.println("C:" + e.getClass() + "\nM:" + e.getMessage());
        return null;
    } catch (TransformerException e) {
        System.out.println("C:" + e.getClass() + "\nM:" + e.getMessage());
        return null;
    }
    return xmlString;
}