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); } }
/** * 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(); }
/** * 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(); }
protected Document parseDocument(Reader reader) throws ParseException { nodeCache.clear(); try { String xmlData = IOUtils.toString(reader); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(parserOptions.isNamespaceAware()); dbf.setValidating(parserOptions.isValidating()); dbf.setIgnoringComments(parserOptions.isIgnoringComments()); dbf.setIgnoringElementContentWhitespace(parserOptions.isIgnoringElementContentWhitespace()); dbf.setExpandEntityReferences(parserOptions.isExpandEntityReferences()); dbf.setCoalescing(parserOptions.isCoalescing()); dbf.setXIncludeAware(parserOptions.isXincludeAware()); dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); DocumentBuilder documentBuilder = dbf.newDocumentBuilder(); documentBuilder.setEntityResolver(parserOptions.getEntityResolver()); Document document = documentBuilder.parse(new InputSource(new StringReader(xmlData))); DOMLineNumbers lineNumbers = new DOMLineNumbers(document, xmlData); lineNumbers.determine(); return document; } catch (ParserConfigurationException | SAXException | IOException e) { throw new ParseException(e); } }
DocumentBuilderFactory.newInstance(); dfactory.setCoalescing(true); dfactory.setNamespaceAware(true);
/** * loadConfig purpose. * * <p>Parses the specified file into a DOM tree. * * @param configFile The file to parse int a DOM tree. * @return the resulting DOM tree * @throws ParserConfigurationException DOCUMENT ME! * @throws ParserConfigurationException * @throws SAXException DOCUMENT ME! */ public static Element loadConfig(Reader configFile) throws IOException, ParserConfigurationException, SAXException { LOGGER.finest("loading configuration file " + configFile); InputSource in = new InputSource(configFile); DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); dfactory.setNamespaceAware(true); // TODO turn on validation dfactory.setValidating(false); dfactory.setIgnoringComments(true); dfactory.setCoalescing(true); dfactory.setIgnoringElementContentWhitespace(true); Document serviceDoc = dfactory.newDocumentBuilder().parse(in); Element configElem = serviceDoc.getDocumentElement(); return configElem; }
private Document createDocument(InputSource inputSource) { // important: this must only be called AFTER common constructor try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(validation); factory.setNamespaceAware(false); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(false); factory.setCoalescing(false); factory.setExpandEntityReferences(true); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setEntityResolver(entityResolver); builder.setErrorHandler(new ErrorHandler() { @Override public void error(SAXParseException exception) throws SAXException { throw exception; } @Override public void fatalError(SAXParseException exception) throws SAXException { throw exception; } @Override public void warning(SAXParseException exception) throws SAXException { } }); return builder.parse(inputSource); } catch (Exception e) { throw new BuilderException("Error creating document instance. Cause: " + e, e); } }
private Document createDocument(InputSource inputSource) { // important: this must only be called AFTER common constructor try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(validation); factory.setNamespaceAware(false); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(false); factory.setCoalescing(false); factory.setExpandEntityReferences(true); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setEntityResolver(entityResolver); builder.setErrorHandler(new ErrorHandler() { @Override public void error(SAXParseException exception) throws SAXException { throw exception; } @Override public void fatalError(SAXParseException exception) throws SAXException { throw exception; } @Override public void warning(SAXParseException exception) throws SAXException { } }); return builder.parse(inputSource); } catch (Exception e) { throw new BuilderException("Error creating document instance. Cause: " + e, e); } }
dfactory.setCoalescing(true); dfactory.setIgnoringElementContentWhitespace(true);
@Override public void setCoalescing (final boolean coalescing) { _WrappedFactory.setCoalescing (coalescing); }
@Override public void setCoalescing (final boolean coalescing) { _WrappedFactory.setCoalescing (coalescing); }
private static DocumentBuilderFactory createDocumentBuilderFactory() { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setCoalescing(true); factory.setIgnoringComments(true); return factory; }
private static DocumentBuilderFactory createDocumentBuilderFactory() { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setCoalescing(true); factory.setIgnoringComments(true); factory.setExpandEntityReferences(false); return factory; }
public static DocumentBuilder newDocumentBuilder(boolean nsAware, boolean validating, boolean coalescing, boolean ignoreComments) throws ParserConfigurationException{ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(nsAware); factory.setValidating(validating); factory.setCoalescing(coalescing); factory.setIgnoringComments(ignoreComments); return factory.newDocumentBuilder(); }
private DocumentBuilderFactory getBaseDBF() { // Use JAXP to create a document builder DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setExpandEntityReferences(false); factory.setValidating(true); factory.setNamespaceAware(true); factory.setIgnoringComments(true); factory.setCoalescing(true); factory.setIgnoringElementContentWhitespace(true); return factory; }
public DomBuilder() { builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setValidating(false); builderFactory.setNamespaceAware(false); builderFactory.setCoalescing(false); try { builder = builderFactory.newDocumentBuilder(); document = builder.newDocument(); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } }
public void createDocument(File xmlFile) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setIgnoringComments(true); builderFactory.setCoalescing(true); builderFactory.setIgnoringElementContentWhitespace(true); builderFactory.setValidating(false); DocumentBuilder builder = builderFactory.newDocumentBuilder(); doc = builder.parse(xmlFile); }
private Element parseXML(String name, String xml) { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(true); builderFactory.setCoalescing(true); builderFactory.setIgnoringElementContentWhitespace(true); builderFactory.setIgnoringComments(true); try { return builderFactory.newDocumentBuilder().parse(new InputSource(new StringReader(xml))).getDocumentElement(); } catch(Exception e) { throw new ComponentDefinitionException(String.format("Error %s parsing XML: %s", name, xml)); } }
public void setGroovity(Groovity groovity){ this.httpClient=groovity.getHttpClient(); this.docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setNamespaceAware(true); docBuilderFactory.setIgnoringElementContentWhitespace(true); docBuilderFactory.setCoalescing(true); docBuilderFactory.setIgnoringComments(true); docBuilderFactory.setValidating(false); this.asyncExecutor = groovity.getAsyncExecutor(); } @SuppressWarnings({"rawtypes","unchecked"})
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setCoalescing(true); dbf.setIgnoringElementContentWhitespace(true); dbf.setIgnoringComments(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc1 = db.parse(new File("file1.xml")); doc1.normalizeDocument(); Document doc2 = db.parse(new File("file2.xml")); doc2.normalizeDocument(); Assert.assertTrue(doc1.isEqualNode(doc2));