Java XML Parse File parseData(String filename)

Here you can find the source of parseData(String filename)

Description

parse Data

License

Open Source License

Declaration

public static Document parseData(String filename) 

Method Source Code


//package com.java2s;
/*/*from  www.  java  2  s .co  m*/
 * XMLUtility.java  2/6/13 1:04 PM
 *
 * Copyright (C) 2012-2013 Nick Ma
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;

import org.xml.sax.SAXException;

public class Main {
    public static Document parseData(String filename) {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        Document document = null;
        try {
            DocumentBuilder myDoc = factory.newDocumentBuilder();
            File xmlFile = new File(filename);
            document = myDoc.parse(xmlFile);
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();
        }
        return document;
    }
}

Related

  1. parse(String fileName)
  2. parse(String fileName)
  3. parse(String filename)
  4. parse(String xmlFile)
  5. parseAIMLFile(File file)
  6. parseDoc(File xmlFile)
  7. parseFile(Class context, String name)
  8. parseFile(File file)
  9. parseFile(File fn)