Here you can find the source of elementToXMLString(Object aElement)
public static String elementToXMLString(Object aElement) throws TransformerException
//package com.java2s; /*/*from www.ja v a2s. com*/ * IST-FP6-034763 QualiPSo: QualiPSo is a unique alliance * of European, Brazilian and Chinese ICT industry players, * SMEs, governments and academics to help industries and * governments fuel innovation and competitiveness with Open * Source software. To meet that goal, the QualiPSo consortium * intends to define and implement the technologies, processes * and policies to facilitate the development and use of Open * Source software components, with the same level of trust * traditionally offered by proprietary software. QualiPSo is * partially funded by the European Commission under EU?s sixth * framework program (FP6), as part of the Information Society * Technologies (IST) initiative. * * This program has been created as part of the QualiPSo work * package on "Semantic Interoperability". The basic idea of this work * package is to demonstrate how semantic technologies can be used to * cope with the diversity and heterogeneity of software and services * in the OSS domain. * * You can redistribute this program and/or modify it under the terms * of the GNU Lesser General Public License version 3 (LGPL v3.0). * * This program 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. * * You should have received a copy of the LGPL * along with this program; if not, please have a look at * http://www.gnu.org/licenses/lgpl.html * to obtain the full license text. * * Author of this program: * Fraunhofer Institute FOKUS, http://www.fokus.fraunhofer.de * * */ 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.Node; public class Main { /** * Property for setting indent levels. */ protected static final String INDENT_AMOUNT_XALAN = "{http://xml.apache.org/xalan}indent-amount"; public static String elementToXMLString(Object aElement) throws TransformerException { DOMSource source = new DOMSource((Node) aElement); StringWriter stringWriter = new StringWriter(); StreamResult result = new StreamResult(stringWriter); TransformerFactory tfactory = TransformerFactory.newInstance(); if (tfactory.getFeature(DOMSource.FEATURE) && tfactory.getFeature(StreamResult.FEATURE)) { Transformer transformer = tfactory.newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(INDENT_AMOUNT_XALAN, "3"); transformer.transform(source, result); } return stringWriter.toString(); } }