public XMLUserGroupService() throws IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setIgnoringComments(true); try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new IOException(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); }
public WsdlMapFactoryImpl() throws ParserConfigurationException { domFactory.setNamespaceAware(true); domFactory.setIgnoringComments(true); builder = domFactory.newDocumentBuilder(); };
public XMLRoleService() throws IOException { super(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setIgnoringComments(true); try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new IOException(e); } }
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; }
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setIgnoringComments(true); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse(new File("XmlTest.xml")); NodeList nodes = doc.getElementsByTagName("CustomerId"); Text a = doc.createTextNode("value"); Element p = doc.createElement("newNode"); p.appendChild(a); nodes.item(0).getParentNode().insertBefore(p, nodes.item(0));
public static DocumentBuilderFactory getFactory() { DocumentBuilderFactory factory = Util.createDocumentBuilderFactory(); factory.setNamespaceAware(true); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); return factory; }
private static Source mergeIntoSource(InputStream baseXmlStream, InputStream xmlStream) throws Exception { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setIgnoringComments(true); domFactory.setValidating(false); domFactory.setNamespaceAware(true); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document baseDoc = builder.parse(baseXmlStream); Document ruleDoc = builder.parse(xmlStream); // Shall this be more generic, i.e. reuse not just unification ??? NodeList unificationNodes = baseDoc.getElementsByTagName("unification"); Node ruleNode = ruleDoc.getElementsByTagName("rules").item(0); Node firstChildRuleNode = ruleNode.getChildNodes().item(1); for (int i = 0; i < unificationNodes.getLength(); i++) { Node unificationNode = ruleDoc.importNode(unificationNodes.item(i), true); ruleNode.insertBefore(unificationNode, firstChildRuleNode); } return new DOMSource(ruleDoc); }
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 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 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 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; }
/** * 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(); docBuilderFactory.setIgnoringComments(true); docBuilderFactory.setNamespaceAware(true); try { docBuilderFactory.setXIncludeAware(true); e); DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); Document doc = null; Element root = null;
private void forgeAndOpenDocument(String xmlValue) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); DocumentBuilder documentBuilder = factory.newDocumentBuilder(); Document document = documentBuilder.parse( new ByteArrayInputStream(xmlValue.getBytes(UTF_8))); parser = new XmlResourceParserImpl( document, Paths.get("file"), R.class.getPackage().getName(), "org.robolectric", null); // Navigate to the root element parseUntilNext(XmlResourceParser.START_TAG); } catch (Exception parsingException) { // Wrap XML parsing exception with a runtime // exception for convenience. throw new RuntimeException( "Cannot forge a Document from an invalid XML", parsingException); } }
dbf.setIgnoringComments( true ); dbf.setNamespaceAware( namespaceAware ); DocumentBuilder db = dbf.newDocumentBuilder(); doc = db.parse( inputStream ); } else { systemIDwithEndingSlash = systemIDwithEndingSlash.concat( "/" ); doc = db.parse( inputStream, systemIDwithEndingSlash );
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); factory.setValidating(true); final DocumentBuilder builder = factory.newDocumentBuilder(); final XmlErrorHandler errorHandler = new XmlErrorHandler(systemLogWriter, xmlDocumentUri); builder.setErrorHandler(errorHandler); builder.setEntityResolver(new AuthzDtdResolver()); final Document xmlDocument = builder.parse(xmlDocumentUri);
/** * Ensures the namespace declared by {@link ClusteringCacheManagerServiceConfigurationParser} and its * schema are the same. */ @Test public void testSchema() throws Exception { final ClusteringCacheManagerServiceConfigurationParser parser = new ClusteringCacheManagerServiceConfigurationParser(); final StreamSource schemaSource = (StreamSource) parser.getXmlSchema(); final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); final DocumentBuilder domBuilder = factory.newDocumentBuilder(); final Element schema = domBuilder.parse(schemaSource.getInputStream()).getDocumentElement(); final Attr targetNamespaceAttr = schema.getAttributeNode("targetNamespace"); assertThat(targetNamespaceAttr, is(not(nullValue()))); assertThat(targetNamespaceAttr.getValue(), is(parser.getNamespace().toString())); }