DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true); factory.setIgnoringElementContentWhitespace(true); try { DocumentBuilder builder = factory.newDocumentBuilder(); File file = new File("test.xml"); Document doc = builder.parse(file); // Do something with the document here. } catch (ParserConfigurationException e) { } catch (SAXException e) { } catch (IOException e) { }
/** * Returns the DOM parser implementation that is used when building {@link NodeModel} objects from XML files or from * {@link InputStream} with the static convenience methods of {@link NodeModel}. Otherwise FreeMarker itself doesn't * use this. * * @see #setDocumentBuilderFactory(DocumentBuilderFactory) */ static public DocumentBuilderFactory getDocumentBuilderFactory() { synchronized (STATIC_LOCK) { if (docBuilderFactory == null) { DocumentBuilderFactory newFactory = DocumentBuilderFactory.newInstance(); newFactory.setNamespaceAware(true); newFactory.setIgnoringElementContentWhitespace(true); docBuilderFactory = newFactory; // We only write it out when the initialization was full } return docBuilderFactory; } }
private static DocumentBuilderFactory createAndGetFactory(Collection<Source> schemaSources) throws SAXException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); factory.setSchema(newSchema(schemaSources.toArray(new Source[schemaSources.size()]))); return factory; }
private B2BParserHelper(){ DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setValidating(false); // It's not needed to validate here builderFactory.setIgnoringElementContentWhitespace(true); try { builder = builderFactory.newDocumentBuilder(); // Create the parser } catch(ParserConfigurationException e) { throw new RuntimeException(e); } }
/** * allows subclasses to configure the {@link DocumentBuilderFactory}. * @param dbf the factory to configure */ protected void configureFactory(DocumentBuilderFactory dbf) { dbf.setValidating(true); dbf.setIgnoringComments(false); dbf.setIgnoringElementContentWhitespace(false); dbf.setNamespaceAware(true); protectAgainstXxeAttacks(dbf); }
private static synchronized Document parse(Path xmlFile) { InputStream inputStream = null; try { if (documentBuilder == null) { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilderFactory.setIgnoringComments(true); documentBuilderFactory.setIgnoringElementContentWhitespace(true); documentBuilder = documentBuilderFactory.newDocumentBuilder(); } inputStream = Fs.getInputStream(xmlFile); return documentBuilder.parse(inputStream); } catch (ParserConfigurationException | IOException | SAXException e) { throw new RuntimeException(e); } finally { if (inputStream != null) try { inputStream.close(); } catch (IOException e) { // ignore } } }
private static DocumentBuilderFactory createFactory() { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setIgnoringComments(false); factory.setIgnoringElementContentWhitespace(true); return factory; }
/***********************************************************************/ private static Document createDocument() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(false); documentBuilderFactory.setIgnoringElementContentWhitespace(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); return documentBuilder.getDOMImplementation().createDocument("", "XML", null); } /***********************************************************************/
/** * Create a JAXP DocumentBuilderFactory that this bean definition reader will use for parsing XML documents. Can be * overridden in subclasses, adding further initialization of the factory. * * @return the JAXP DocumentBuilderFactory */ private DocumentBuilderFactory createDocumentBuilderFactory() { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true); factory.setNamespaceAware(true); factory.setIgnoringElementContentWhitespace(true); factory.setAttribute(SCHEMA_FEATURE, true); // For Xerces implementation return factory; }
protected static DocumentBuilderFactory getDocumentBuilderFactory() { DocumentBuilderFactory factory; try { factory = XmlParserFactoryProducer.createSecureDocBuilderFactory(); } catch (ParserConfigurationException ex) { throw new XmlaException( SERVER_FAULT_FC, SIE_REQUEST_STATE_CODE, SIE_REQUEST_STATE_FAULT_FS, ex); } factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); factory.setNamespaceAware(true); return factory; }
private DocumentBuilder documentBuilder() { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setCoalescing(true); dbf.setIgnoringElementContentWhitespace(true); dbf.setIgnoringComments(true); try { return dbf.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new MocoException(e); } }
public static DocumentBuilderFactory getFactory() { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); return factory; }
public static DocumentBuilderFactory getFactory() { DocumentBuilderFactory factory = Util.createDocumentBuilderFactory(); factory.setNamespaceAware(true); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); return factory; }
public static DocumentBuilder documentBuilder(Schema schema) throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); factory.setSchema(schema); DocumentBuilder documentBuilder = factory.newDocumentBuilder(); documentBuilder.setErrorHandler(new FatalErrorHandler()); return documentBuilder; }
private static DocumentBuilderFactory createFactory() { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setIgnoringComments(false); factory.setIgnoringElementContentWhitespace(true); return factory; }
public static DocumentBuilderFactory getFactory() { DocumentBuilderFactory factory = Util.createDocumentBuilderFactory(); factory.setNamespaceAware(true); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); return factory; }
/** * Parses the specified reader into a DOM tree. * * @param xml Reader representing xml stream to parse. * @return the root element of resulting DOM tree * @throws RuntimeException If reader failed to parse properly. */ public static Element parse(Reader xml) { InputSource in = new InputSource(xml); DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); dfactory.setNamespaceAware(false); dfactory.setValidating(false); dfactory.setIgnoringComments(true); dfactory.setCoalescing(true); dfactory.setIgnoringElementContentWhitespace(true); Document doc; try { doc = dfactory.newDocumentBuilder().parse(in); } catch (Exception e) { String msg = "Error reading : " + xml; throw new RuntimeException(msg, e); } return doc.getDocumentElement(); }
public DocumentLoader(XmlLoader... xmlLoaders) { this.xmlLoaders = xmlLoaders; documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilderFactory.setIgnoringComments(true); documentBuilderFactory.setIgnoringElementContentWhitespace(true); }
public static DocumentBuilderFactory getFactory() { DocumentBuilderFactory factory = Util.createDocumentBuilderFactory(); factory.setNamespaceAware(true); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); return factory; }
/** * Parses the specified reader into a DOM tree. * * @param xml Reader representing xml stream to parse. * @return the root element of resulting DOM tree * @throws RuntimeException If reader failed to parse properly. */ public static Element parse(Reader xml) { InputSource in = new InputSource(xml); DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); dfactory.setNamespaceAware(false); dfactory.setValidating(false); dfactory.setIgnoringComments(true); dfactory.setCoalescing(true); dfactory.setIgnoringElementContentWhitespace(true); Document doc; try { doc = dfactory.newDocumentBuilder().parse(in); } catch (Exception e) { String msg = "Error reading : " + xml; throw new RuntimeException(msg, e); } return doc.getDocumentElement(); }