List of utility methods to do XML Parse InputSource
Document | parse(final InputSource is, final Class loader) parse DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema"); factory.setNamespaceAware(true); factory.setValidating(true); DocumentBuilder parser = factory.newDocumentBuilder(); final Map<String, String> system = new HashMap<String, String>(); system.put("http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd", "/schema/jboss-ejb3-2_0.xsd"); ... |
Document | parse(InputSource in) parse try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); return db.parse(in); } catch (Exception e) { e.printStackTrace(); return null; |
Document | parse(InputSource input, boolean validate, boolean namespaceAware, ErrorHandler errorHandler, EntityResolver entityResolver) Parses an XML document into a DOM tree. DocumentBuilder builder = null; DocumentBuilderFactory factory = getFactory(validate, namespaceAware); try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException ex) { throw new SAXException("Cannot create parser satisfying configuration parameters", ex); if (errorHandler != null) { ... |
Element | parse(InputSource source) Parse the given input source and return the root Element try { return getDocumentBuilder().parse(source).getDocumentElement(); } catch (SAXException se) { throw new IOException(se.toString()); } finally { InputStream is = source.getByteStream(); if (is != null) { is.close(); ... |
Document | parseXML(InputSource is) Parses an input source and generates an XML document. try { Document doc = null; DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); doc = documentBuilder.parse(is); return doc; } catch (Exception e) { throw new RuntimeException("Failed to parse XML source", e); |