Here you can find the source of xmlDocumentDecode(final String xmlURI)
Parameter | Description |
---|---|
xmlURI | the xml uri |
Parameter | Description |
---|---|
Exception | the exception |
public static final Element xmlDocumentDecode(final String xmlURI) throws Exception
//package com.java2s; /**/*from w w w.java2 s .c o m*/ * Copyright (C) 2011-2012 Barchart, Inc. <http://www.barchart.com/> * * All rights reserved. Licensed under the OSI BSD License. * * http://www.opensource.org/licenses/bsd-license.php */ import java.io.ByteArrayInputStream; import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { private static final ThreadLocal<DocumentBuilder> XML_BUILDER = new ThreadLocal<DocumentBuilder>() { @Override protected DocumentBuilder initialValue() { try { final DocumentBuilder builder = DocumentBuilderFactory .newInstance().newDocumentBuilder(); return builder; } catch (final Exception e) { throw new RuntimeException(e); } } }; /** * Xml document decode. * * @param xmlURI * the xml uri * @return the element * @throws Exception * the exception */ public static final Element xmlDocumentDecode(final String xmlURI) throws Exception { return XML_BUILDER.get().parse(xmlURI).getDocumentElement(); } /** * Xml dodument decode. * * @param array * the array * @param start * the start * @param finish * the finish * @param isThrow * the is throw * @return the element */ public static final Element xmlDocumentDecode(final byte[] array, final int start, final int finish, final boolean isThrow) { final InputStream stream = new ByteArrayInputStream(array, start, finish); try { final Document document = XML_BUILDER.get().parse(stream); return document.getDocumentElement(); } catch (final Exception e) { // will return/throw below } if (isThrow) { throw new RuntimeException("can not decode : \n" + new String(array)); } return null; } }