Java XML Parse String parse(String input)

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

Description

parse

License

Open Source License

Declaration

public static Document parse(String input) throws SAXException, ParserConfigurationException 

Method Source Code

//package com.java2s;
// This file is part of nzdis-util package. See the file LICENSE for copyright information

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

import java.io.Reader;
import java.io.StringReader;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class Main {
    public static Document parse(InputStream input, Properties props)
            throws SAXException, ParserConfigurationException {
        return parse(new InputSource(input), props);
    }//from   ww  w .  j  ava 2 s  .  com

    public static Document parse(String input) throws SAXException, ParserConfigurationException {
        return parse(new StringReader(input), null);
    }

    public static Document parse(Reader input) throws SAXException, ParserConfigurationException {
        return parse(new InputSource(input), null);
    }

    public static Document parse(Reader input, Properties props) throws SAXException, ParserConfigurationException {
        return parse(new InputSource(input), props);
    }

    public static Document parse(InputSource input, @SuppressWarnings("unused") Properties props)
            throws SAXException, ParserConfigurationException {

        Document doc = null;
        try {
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            doc = docBuilder.parse(input);

        } catch (IOException e) {
            e.printStackTrace(System.out);
            //throw e;
        }

        return doc;
    }
}

Related

  1. parse(final String content)
  2. parse(final String line)
  3. parse(final String xmlContent)
  4. parse(String input, char delim, char esc)
  5. parse(String line)
  6. parse(String line)
  7. parse(String s)