Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.IOException;

import java.io.StringReader;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

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

public class Main {
    /**
     * Get root element from XML String
     * 
     * @param arg
     *            XML String
     * @return Root Element
     * @throws ParserConfigurationException
     * @throws SAXException
     * @throws IOException
     */
    public static Element getDocumentElementFromString(String arg)
            throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilderFactory dbf;
        DocumentBuilder db;
        Document document;
        dbf = DocumentBuilderFactory.newInstance();
        db = dbf.newDocumentBuilder();
        document = db.parse(new InputSource(new StringReader(arg)));
        Element element = document.getDocumentElement();
        return element;

    }
}