Java XML String Transform parseToString(final Node node)

Here you can find the source of parseToString(final Node node)

Description

parse To String

License

Open Source License

Declaration

public static String parseToString(final Node node)
            throws TransformerFactoryConfigurationError, TransformerException 

Method Source Code

//package com.java2s;
/**//  ww  w . java2 s .com
 * PETALS - PETALS Services Platform. Copyright (c) 2007 EBM Websourcing,
 * http://www.ebmwebsourcing.com/
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version. This library is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * 
 * -------------------------------------------------------------------------
 * $Id: Router.java,v 1.2 2006/03/17 10:24:27 alouis Exp $
 * -------------------------------------------------------------------------
 */

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.Node;

public class Main {
    public static String parseToString(final Node node)
            throws TransformerFactoryConfigurationError, TransformerException {
        String result = null;
        if (node != null) {
            node.normalize();
            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            StringWriter stringWriter = new StringWriter();
            transformer.transform(new DOMSource(node), new StreamResult(stringWriter));
            StringBuffer buffer = stringWriter.getBuffer();
            result = buffer.toString();
        }
        return result;
    }
}

Related

  1. indentXML(String fileContent)
  2. loadSourceFromURL(String systemID)
  3. mergeXml(String... xmlSources)
  4. normXML(String s)
  5. parseEventsToXML(String module, Hashtable keyvalues)
  6. parseXmlFile(String filename, boolean validating, boolean namespaceAware)
  7. readFile(String fileName)
  8. readFile(String systemId)
  9. readURL(String urlStr)