Read in an existing document.
try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware( true); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse( new Inputsource( "test.xml")); } catch ( ParserConfigurationException e) { e.printStackTrace(); } catch ( SAXException e) { e.printStackTrace(); } catch ( IOException e) { e.printStackTrace(); }
Create a new document.
try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware( true); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); } catch ( ParserConfigurationException e) { e.printStackTrace(); } catch ( SAXException e) { e.printStackTrace(); } catch ( IOException e) { e.printStackTrace(); }