Java XML Transform Usage convert(final Element element)

Here you can find the source of convert(final Element element)

Description

convert

License

Open Source License

Declaration

public static String convert(final Element element) throws NullPointerException, TransformerException 

Method Source Code

//package com.java2s;
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

import java.io.StringWriter;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Element;

public class Main {
    public static String convert(final Element element) throws NullPointerException, TransformerException {
        if (null == element) {
            throw new NullPointerException("connot convert null DOM Element");
        }//from ww w .jav  a2  s  .co m

        TransformerFactory transFactory = TransformerFactory.newInstance();
        Transformer transformer = transFactory.newTransformer();

        StringWriter stringWriter = new StringWriter();
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.transform(new DOMSource(element), new StreamResult(stringWriter));

        return stringWriter.toString();
    }
}

Related

  1. bytesToXml(final byte[] body)
  2. castResultToSource(StreamResult result)
  3. closeSource(final Source source)
  4. compareSource(Source src, Source target)
  5. compareStreamSource(StreamSource src1, StreamSource src2)
  6. convertDisplay(Object object)
  7. convertMessageToInputStream(Source src)
  8. createAndGetFactory(Collection schemaSources)
  9. createDefaultPropertiesForXML(boolean omitXMLDeclaration)