Java Utililty Methods XML Document from File

List of utility methods to do XML Document from File

Description

The list of methods to do XML Document from File are organized into topic(s).

Method

DocumentreadXML(File file)
Reads XML from a file
return getXML(new FileInputStream(file));
DocumentreadXml(File file)
read Xml
return readXml(new FileInputStream(file));
DocumentreadXML(File xml)
read XML
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(true);
DocumentBuilder builder = builderFactory.newDocumentBuilder();
return builder.parse(xml);
DocumentreadXml(String path)
read Xml
File in = new File(path);
if (!in.exists())
    return null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
    DocumentBuilder db = dbf.newDocumentBuilder();
    return db.parse(in);
} catch (IOException ex) {
...
DocumentreadXML(String path)
Read xml from file
try {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    return builder.parse(new File(path));
} catch (Exception e) {
    e.printStackTrace();
    return null;
DocumentreadXMLFile(File file)
read XML File
return readXMLFile(file, null);
DocumentreadXmlFile(String fileName)
Parse the content of the given file as an XML document and return a new DOM
Document doc = null;
try {
    File xmlFile = new File(fileName);
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setNamespaceAware(false);
    DocumentBuilder builder = domFactory.newDocumentBuilder();
    doc = builder.parse(xmlFile);
} catch (ParserConfigurationException e) {
...
NodereadXMLFile(String filename)
Reads an XML document and returns the root node (which is all you need 99% of the time)
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = null;
try {
    document = builder.parse(new File(filename));
} catch (SAXParseException spe) {
    String errtxt = "parse error in " + spe.getSystemId() + ",\nline: " + spe.getLineNumber() + " "
...
DocumentreadXmlFile(String fileName)
parse xmlFile in a Document
Document doc = null;
try {
    File xmlFile = new File(fileName);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = factory.newDocumentBuilder();
    doc = docBuilder.parse(xmlFile);
} catch (Exception e) {
    System.out.println("Error on parsing XML file : " + fileName);
...
DocumentreadXMLFile(String filename)
Reads the xml file and returns the Document of it.
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = null;
try {
    dBuilder = dbFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
    e.printStackTrace();
assert dBuilder != null;
...