List of usage examples for javax.xml.parsers DocumentBuilderFactory setNamespaceAware
public void setNamespaceAware(boolean awareness)
From source file:Main.java
private static DocumentBuilder buildDocumentBuilder(boolean namespaceAware) throws ParserConfigurationException { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setNamespaceAware(namespaceAware); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); return docBuilder; }
From source file:Main.java
/** * Initialize the document builder//w w w . j a v a2 s . co m * * @param namespaceAware - indicates which document builder to be initialized * @throws Exception */ private static void initializeDocumentBuilder(boolean namespaceAware) throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(namespaceAware); if (namespaceAware) { docBuilder_NS_Aware = documentBuilderFactory.newDocumentBuilder(); } else { docBuilder_NS_Unaware = documentBuilderFactory.newDocumentBuilder(); } }
From source file:Main.java
public static DocumentBuilder newDocumentBuilder(boolean validating) { try {/*www. j a va 2 s .c o m*/ DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); dbfac.setNamespaceAware(true); dbfac.setValidating(validating); return dbfac.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static DocumentBuilder newDocumentBuilder(Boolean disallowDoctypeDecl) throws ParserConfigurationException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(false);/*w w w .j a v a 2 s .c o m*/ // avoid external entity attacks dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); boolean isDissalowDoctypeDecl = disallowDoctypeDecl == null ? true : disallowDoctypeDecl; dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", isDissalowDoctypeDecl); // avoid overflow attacks dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); return dbf.newDocumentBuilder(); }
From source file:Main.java
public static Document string2Document(String xml) throws Exception { InputSource src = new InputSource(new StringReader(xml)); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setNamespaceAware(true); return dbFactory.newDocumentBuilder().parse(src); }
From source file:Main.java
private static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); // Unfortunately we can not ignore whitespaces without a schema. // So we use the NdLst workaround for now. domFactory.setAttribute("http://apache.org/xml/features/dom/include-ignorable-whitespace", Boolean.FALSE); return domFactory.newDocumentBuilder(); }
From source file:Main.java
public static Document getDocument() throws ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); return documentBuilderFactory.newDocumentBuilder().newDocument(); }
From source file:Main.java
private static Document createDocument() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(XMLSTRING.getBytes("ISO-8859-1"))); return doc;/*from w w w .java 2 s . c o m*/ }
From source file:Main.java
private static Document getDoc(String filePath) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = null; XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); builder = factory.newDocumentBuilder(); Document doc = builder.parse(filePath); return doc;/*from ww w. ja v a2 s .c o m*/ }
From source file:Main.java
/** * * @param xml//w w w. j a va 2s . c o m * @return * @throws SAXException * @throws ParserConfigurationException * @throws IOException */ public static Document bytesToDom(byte[] xml) throws SAXException, ParserConfigurationException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new ByteArrayInputStream(xml)); }