Here you can find the source of byteArrayToElement(byte[] b, boolean namespaceAware)
Parameter | Description |
---|
public static Element byteArrayToElement(byte[] b, boolean namespaceAware) throws ParserConfigurationException, SAXException, UnsupportedEncodingException, IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from www. j a v a2 s . c o m*/ * IBM Corporation - initial API and implementation *******************************************************************************/ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; public class Main { /** * Convert the byte array representation of an Element into an Element * @param byte[] representation of an Element. * @param boolean set whether the return Element should be namespace aware. * @return Element */ public static Element byteArrayToElement(byte[] b, boolean namespaceAware) throws ParserConfigurationException, SAXException, UnsupportedEncodingException, IOException { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setNamespaceAware(namespaceAware); docBuilderFactory.setValidating(false); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(new ByteArrayInputStream(b)); return doc.getDocumentElement(); } }