Java XML Parse File parse(String fileName)

Here you can find the source of parse(String fileName)

Description

parse

License

Open Source License

Declaration

public static Document parse(String fileName) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009 CollabNet./*from ww w .j ava 2 s  .  c o  m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     CollabNet - initial API and implementation
 ******************************************************************************/

import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

public class Main {
    public static Document parse(String fileName) {
        Document document = null;
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

        factory.setValidating(false);
        factory.setNamespaceAware(true);

        try {
            DocumentBuilder builder = factory.newDocumentBuilder();
            document = builder.parse(new File(fileName));
            return document;
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

        return null;
    }
}

Related

  1. parse(File xml, ErrorHandler errorHandler)
  2. parse(String fileName)
  3. parse(String fileName)
  4. parse(String filename)
  5. parse(String filename)
  6. parse(String fileName)
  7. parse(String xmlFile)
  8. parseAIMLFile(File file)
  9. parseData(String filename)