Java XML Node Serialize serializeElement(Element element)

Here you can find the source of serializeElement(Element element)

Description

serialize Element

License

Open Source License

Declaration

public static String serializeElement(Element element)
            throws TransformerFactoryConfigurationError, TransformerException 

Method Source Code


//package com.java2s;
import java.io.StringWriter;

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

import org.w3c.dom.Element;

public class Main {
    public static String serializeElement(Element element)
            throws TransformerFactoryConfigurationError, TransformerException {
        String serializedElement = null;
        if (element != null) {
            StringWriter output = new StringWriter();

            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            transformer.transform(new DOMSource(element), new StreamResult(output));

            serializedElement = output.toString();
        }//  www.  jav a  2 s  .c  om
        return serializedElement;
    }
}

Related

  1. serialize(Node node)
  2. serialize(Node node, File outdir, String fileName)
  3. serialize(NodeList nodeList)
  4. serializeDom(Node domElement)
  5. serializeDom(Node node, StringBuffer writeString)
  6. serializeElement(Element element, boolean omitXmlDeclaration, boolean indent, String method)
  7. serializeNode(Node node)
  8. serializeNode(Node node)
  9. serializeNode(Node node)