Java XML Parse File parse(File f, DefaultHandler dh)

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

Description

parse

License

Open Source License

Declaration

public static void parse(File f, DefaultHandler dh) throws SAXException, IOException 

Method Source Code


//package com.java2s;
/*//from   w w w  . j  a va  2 s .c o  m
 * dbXML - Native XML Database
 * Copyright (c) 1999-2006 The dbXML Group, L.L.C.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * $Id: SAXHelper.java,v 1.4 2006/02/02 19:04:46 bradford Exp $
 */

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

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.DefaultHandler;

public class Main {
    private static SAXParserFactory spf;

    public static void parse(InputStream is, DefaultHandler dh) throws SAXException, IOException {
        SAXParser sp = createSAXParser(dh);
        sp.parse(is, dh);
    }

    public static void parse(InputStream is, DefaultHandler dh, String systemId) throws SAXException, IOException {
        SAXParser sp = createSAXParser(dh);
        sp.parse(is, dh, systemId);
    }

    public static void parse(File f, DefaultHandler dh) throws SAXException, IOException {
        SAXParser sp = createSAXParser(dh);
        sp.parse(f, dh);
    }

    public static void parse(InputSource is, DefaultHandler dh) throws SAXException, IOException {
        SAXParser sp = createSAXParser(dh);
        sp.parse(is, dh);
    }

    private static SAXParser createSAXParser(DefaultHandler dh) throws SAXException {
        try {
            SAXParser sp = spf.newSAXParser();
            if (dh instanceof LexicalHandler)
                sp.setProperty("http://xml.org/sax/properties/lexical-handler", dh);

            return sp;
        } catch (ParserConfigurationException e) {
            throw new SAXException(e);
        }
    }
}

Related

  1. parse(File f)
  2. parse(File f)
  3. parse(File f)
  4. parse(File f, boolean validation)
  5. parse(File file)
  6. parse(File file)
  7. parse(File file)
  8. parse(File file)