Java XML Document from File isXMLFile(File file)

Here you can find the source of isXMLFile(File file)

Description

is XML File

License

GNU General Public License

Parameter

Parameter Description
file aa

Exception

Parameter Description
ParserConfigurationException aa

Return

aa

Declaration

public static boolean isXMLFile(File file)
        throws ParserConfigurationException 

Method Source Code

//package com.java2s;
/* DigiDoc4J library// w  ww.  j a  va 2s  .c  om
 *
 * This software is released under either the GNU Library General Public
 * License (see LICENSE.LGPL).
 *
 * Note that the only valid version of the LGPL license as far as this
 * project is concerned is the original GNU Library General Public License
 * Version 2.1, February 1999
 */

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;

public class Main {
    /**
     * @param file aa
     * @return aa
     * @throws ParserConfigurationException aa
     */
    public static boolean isXMLFile(File file)
            throws ParserConfigurationException {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance()
                .newDocumentBuilder();
        try {
            builder.parse(file);
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}

Related

  1. getXML(File file)
  2. getXML(File xmlFile)
  3. getXmlDocument(File file)
  4. getXmlDocument(File file)
  5. getXmlDocument(String fileName)
  6. load(String file)
  7. load(String sFileName)
  8. loadDocument(File documentFile)
  9. loadDocument(File file)