List of utility methods to do XML Document from File
Document | getDocumentFromFile(File file) get Document From File byte[] document = loadFile(file); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(new ByteArrayInputStream(document)); return doc; |
Document | getDocumentFromFile(String absolutePath) get Document From File DocumentBuilderFactory oDocumentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder oDocumentBuilder = oDocumentBuilderFactory.newDocumentBuilder(); Document oDocument = null; oDocument = oDocumentBuilder.parse(new File(absolutePath)); return oDocument; |
Document | getXML(File file) get XML InputStream in = new FileInputStream(file); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbFactory.newDocumentBuilder(); Document xml = docBuilder.parse(in); in.close(); return xml; |
Document | getXML(File xmlFile) get XML DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(xmlFile);
document.getDocumentElement().normalize();
return document;
|
Document | getXmlDocument(File file) Gets Document representation of xml file try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(file); return doc; } catch (Exception e) { throw new RuntimeException("Could not parse XML document", e); |
Document | getXmlDocument(File file) get Xml Document DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder; try { docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(file); return doc; } catch (ParserConfigurationException e) { return null; ... |
Document | getXmlDocument(String fileName) getXmlDocoument retrieve w3c.Document from given file DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); File f = new File(fileName); if (!f.exists()) { throw new IllegalArgumentException("Test data file " + fileName + " not found!"); return factory.newDocumentBuilder().parse(f); |
boolean | isXMLFile(File file) is XML File DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); try { builder.parse(file); } catch (Exception e) { return false; return true; |
Document | load(String file) load try { Document document = null; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setNamespaceAware(false); DocumentBuilder builder = dbf.newDocumentBuilder(); document = builder.parse(new File(file)); document.normalize(); ... |
Document | load(String sFileName) load if (sFileName != null) { return load(new File(sFileName)); } else { throw new RuntimeException("XML error : load(null) "); |