Java tutorial
//package com.java2s; import java.io.*; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; public class Main { public static Element byteArrayToElement(byte[] cont) { if (cont == null || cont.length <= 0) return null; try { ByteArrayInputStream bais = new ByteArrayInputStream(cont); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setNamespaceAware(false); docBuilderFactory.setValidating(false); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); InputSource is = new InputSource(bais); // is.setEncoding("gb2312"); Document doc = docBuilder.parse(is); return doc.getDocumentElement(); } catch (Exception e) { e.printStackTrace(); return null; } } }