Java XML Parse String parseXml(String xml)

Here you can find the source of parseXml(String xml)

Description

parse Xml

License

Open Source License

Declaration

private static Document parseXml(String xml) 

Method Source Code


//package com.java2s;
/*//  ww w.  j  ava2 s.c o  m
 * This file is part of the Cyprus Fuel Guide server.
 *
 * The Cyprus Fuel Guide server 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 (at your option) any later version.
 *
 * The Cyprus Fuel Guide server 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with Cyprus Fuel Guide. If not, see <http://www.gnu.org/licenses/>.
 */

import org.w3c.dom.Document;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;

import java.util.logging.Logger;

public class Main {
    public static final Logger log = Logger.getLogger("cyprusfuelguide");

    private static Document parseXml(String xml) {
        try {
            final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            final StringReader reader = new StringReader(xml);
            final InputSource inputSource = new InputSource(reader);
            return documentBuilder.parse(inputSource);
        } catch (IOException ioe) {
            log.severe("I/O Error while parsing XML: " + ioe.getMessage());
        } catch (ParserConfigurationException pce) {
            log.severe("Parser Error while parsing XML: " + pce.getMessage());
        } catch (SAXException saxe) {
            log.severe("SAX Error while parsing XML: " + saxe.getMessage());
        }

        return null;
    }
}

Related

  1. parseXML(String text)
  2. parseXml(String uri)
  3. parseXml(String xml)
  4. parseXML(String xml)
  5. parseXML(String xml)
  6. parseXml(String xml)
  7. parseXml(String xmlString)
  8. parseXMLResponse(String xmlStr)
  9. parseXMLString(final String xml)