Java XML Transform Usage bytesToXml(final byte[] body)

Here you can find the source of bytesToXml(final byte[] body)

Description

bytes To Xml

License

Open Source License

Declaration

public static Node bytesToXml(final byte[] body) throws TransformerException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayInputStream;

import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;

import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Node;

public class Main {
    private static final TransformerFactory FACTORY = TransformerFactory.newInstance();

    public static Node bytesToXml(final byte[] body) throws TransformerException {
        final Transformer transformer = FACTORY.newTransformer();
        final Source source = new StreamSource(new ByteArrayInputStream(body));
        final DOMResult result = new DOMResult();
        transformer.transform(source, result);
        return result.getNode();
    }//ww w  .  jav a2s  . com
}

Related

  1. castResultToSource(StreamResult result)
  2. closeSource(final Source source)
  3. compareSource(Source src, Source target)
  4. compareStreamSource(StreamSource src1, StreamSource src2)