Java XML Parse File parse(File f)

Here you can find the source of parse(File f)

Description

parse

License

LGPL

Declaration

public static Document parse(File f) throws SAXException, IOException 

Method Source Code

//package com.java2s;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;

import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class Main {
    private static DocumentBuilder dBuilder;

    public static Document parse(File f) throws SAXException, IOException {
        return dBuilder.parse(f);
    }/*from w w  w . j av  a  2  s.  co m*/

    public static Document parse(InputSource is) throws SAXException,
            IOException {
        return dBuilder.parse(is);
    }

    public static Document parse(InputStream is) throws SAXException,
            IOException {
        return dBuilder.parse(is);
    }

    /**
     * Parse an XML string, NOT that parse(uri) method from the Java APIs.
     * @param xml A XML String
     */
    public static Document parse(String xml) throws SAXException,
            IOException {
        return dBuilder.parse(new InputSource(new StringReader(xml)));
    }

    /**
     * Parses XML from over the network.
     */
    public static Document parse(URL uri) throws SAXException, IOException {
        return dBuilder.parse(uri.toExternalForm());
    }

    public static Document parse(InputStream is, String systemId)
            throws SAXException, IOException {
        return dBuilder.parse(is, systemId);
    }
}

Related

  1. parse(File f)
  2. parse(File f)
  3. parse(File f, boolean validation)
  4. parse(File f, DefaultHandler dh)