List of usage examples for javax.xml.parsers ParserConfigurationException getMessage
public String getMessage()
From source file:Main.java
static public Document getDomElement(String xml) { Document doc = null;/*from w ww .j av a2 s . com*/ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { DocumentBuilder db = dbf.newDocumentBuilder(); //Set the input to our xml string InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xml)); doc = db.parse(is); } catch (ParserConfigurationException e) { Log.e("Error: ", e.getMessage()); return null; } catch (SAXException e) { Log.e("Error: ", e.getMessage()); return null; } catch (IOException e) { Log.e("Error: ", e.getMessage()); return null; } //return DOM return doc; }
From source file:Main.java
public static Document loadXMLFrom(InputStream inputStream) throws Exception { Document doc = null;//from w w w .ja v a2s . c o m DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); javax.xml.parsers.DocumentBuilder builder = null; try { builder = factory.newDocumentBuilder(); doc = builder.parse(inputStream); } catch (ParserConfigurationException pce) { throw new Exception(pce.getMessage()); } catch (SAXException se) { throw new Exception(se.getMessage()); } catch (IOException ioe) { throw new Exception(ioe.getMessage()); } finally { inputStream.close(); } return doc; }
From source file:Main.java
public static Document openXmlFile(File file, boolean validating) { try {//from w ww . j a va 2 s . c o m // Create a builder factory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(validating); // Create the builder and parse the file Document doc = factory.newDocumentBuilder().parse(file); return doc; } catch (SAXException e) { // A parsing error occurred; the xml input is not valid } catch (ParserConfigurationException ex) { System.out.println(ex.getMessage()); } catch (IOException ex) { System.out.println(ex.getMessage()); } return null; }
From source file:Main.java
public static void refreshDocumentBuilder() { if (documentBuilderFactory == null) { refreshDocumentBuilderFactory(); }/*from ww w . j a va 2 s .c o m*/ try { documentBuilder = documentBuilderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { System.out.println("Wrong parser configuration: " + e.getMessage()); } }
From source file:Main.java
/** * open instream for a XML file from URL * * @param the//from w w w . j a v a2 s . c o m * source url * @return the DOM document */ public static Document openXMLStream(URL url) { try { // Create a builder factory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); InputStream stream = url.openStream(); // Create the builder and parse the stream Document doc = factory.newDocumentBuilder().parse(stream); return doc; } catch (SAXException e) { // A parsing error occurred; the xml input is not valid } catch (ParserConfigurationException ex) { System.out.println(ex.getMessage()); } catch (IOException ex) { System.out.println(ex.getMessage()); } return null; }
From source file:Main.java
public static Document startXMLDocument(String _firstTag) { DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = null; Document doc = null;/*from w ww . j av a 2 s. c o m*/ try { docBuilder = dbfac.newDocumentBuilder(); doc = docBuilder.newDocument(); Element xmlRoot = doc.createElement(_firstTag); doc.appendChild(xmlRoot); } catch (ParserConfigurationException e) { System.out.println("C:" + e.getClass() + "\nM:" + e.getMessage()); return null; } return doc; }
From source file:Main.java
/** * Create a new blank XML document./*from w ww . java2s .c o m*/ * * @return The new blank XML document. * * @throws IOException * If there is an error creating the XML document. * @throws ParseException */ public static Document newDocument() throws ParseException { final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; try { builder = builderFactory.newDocumentBuilder(); } catch (final ParserConfigurationException e) { final ParseException thrown = new ParseException(e.getMessage(), 0); throw thrown; } return builder.newDocument(); }
From source file:Main.java
/** * Reads an xml string into XML Document. * //from ww w.ja v a2 s . c o m * @param xmlStr String containing xml * @return xml Document * @throws Exception */ public static Document readXmlString(String xmlStr) throws Exception { Document doc = null; try { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(false); DocumentBuilder builder = domFactory.newDocumentBuilder(); InputSource inStream = new InputSource(); inStream.setCharacterStream(new StringReader(xmlStr)); doc = builder.parse(inStream); } catch (ParserConfigurationException e) { throw new Exception(e.getMessage(), e); } catch (SAXException e) { throw new Exception(e.getMessage(), e); } catch (IOException e) { throw new Exception(e.getMessage(), e); } catch (Exception e) { throw new Exception(e.getMessage(), e); } return doc; }
From source file:Main.java
public static Document xmlFromString(String xml) { Document doc;//from w w w . j ava 2 s . c o m DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xml)); doc = db.parse(is); } catch (ParserConfigurationException e) { System.out.println("XML parse error: " + e.getMessage()); return null; } catch (SAXException e) { System.out.println("Wrong XML file structure: " + e.getMessage()); return null; } catch (IOException e) { System.out.println("I/O exeption: " + e.getMessage()); return null; } return doc; }
From source file:Main.java
public static Document createDocument() throws IOException { DocumentBuilderFactory dBF = DocumentBuilderFactory.newInstance(); DocumentBuilder builder;/*from www .ja v a 2 s .c o m*/ try { builder = dBF.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new IOException("Error creating document builder. (" + e.getMessage() + ")"); } return builder.newDocument(); }