Java XML Node to String asString(XMLStreamReader xmlr)

Here you can find the source of asString(XMLStreamReader xmlr)

Description

as String

License

Apache License

Declaration

public static String asString(XMLStreamReader xmlr) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.StringWriter;

import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamResult;

public class Main {
    public static String asString(XMLStreamReader xmlr) throws Exception {
        Transformer transformer = TransformerFactory.newInstance()
                .newTransformer();//  w  ww  .j a  va2  s . co m
        StringWriter stringWriter = new StringWriter();
        transformer.transform(new StAXSource(xmlr), new StreamResult(
                stringWriter));
        return stringWriter.toString();
    }
}

Related

  1. asString(Element elt)
  2. asString(Node node)
  3. asString(Node node)
  4. asString(Node node)
  5. asXML(Node node)
  6. asXmlString(Node node)
  7. convertToString(Node node)
  8. convertToString(Node node)