private static Document getXml(String response, String encoding) { try { InputSource source = new InputSource(new StringReader(response)); source.setEncoding(encoding); DocumentBuilder builder = XML.newDocumentBuilder(); return builder.parse(source); } catch (Exception e) { throw new RuntimeException(e); } }
/** * parse and get the response body as a {@link Document DOM document} * * @param encoding * xml charset encoding * @return a DOM document */ public Document getXml(String encoding) { try { InputSource source = new InputSource(new StringReader(getString())); source.setEncoding(encoding); DocumentBuilder builder = XML.newDocumentBuilder(); return builder.parse(source); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Parse an XML string content to DOM * * @param xml * The XML string * @return null if an error occurs during parsing. */ public static Document getDocument(String xml) { InputSource source = new InputSource(new StringReader(xml)); try { return newDocumentBuilder().parse(source); } catch (SAXException e) { Logger.warn("Parsing error when building Document object from xml data.", e); } catch (IOException e) { Logger.warn("Reading error when building Document object from xml data.", e); } return null; }
/** * Parse an XML coming from an input stream to DOM * * @param stream * The XML stream * @return null if an error occurs during parsing. */ public static Document getDocument(InputStream stream) { try { return newDocumentBuilder().parse(stream); } catch (SAXException e) { Logger.warn("Parsing error when building Document object from xml data.", e); } catch (IOException e) { Logger.warn("Reading error when building Document object from xml data.", e); } return null; }
/** * Parse an XML file to DOM * * @param file * The XML file * @return null if an error occurs during parsing. * */ public static Document getDocument(File file) { try { return newDocumentBuilder().parse(file); } catch (SAXException e) { Logger.warn("Parsing error when building Document object from xml file '" + file + "'.", e); } catch (IOException e) { Logger.warn("Reading error when building Document object from xml file '" + file + "'.", e); } return null; }