Convert XML dom To Text - Java XML

Java examples for XML:DOM

Description

Convert XML dom To Text

Demo Code


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

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerException;

import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;

public class Main {
    private static Transformer transformer;

    public static String domToText(Document inDocument)
            throws TransformerException {

        StringWriter output = new StringWriter();
        DOMSource source = new DOMSource(inDocument);
        StreamResult result = new StreamResult(output);
        transformer.transform(source, result);
        //this.getWatcher().setProgressText("saved " + getEditedFile().getAbsolutePath());

        return output.toString();

    }// w ww  .  ja  v a2s.  c  o m
}

Related Tutorials