/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ucp.parser;

import java.io.IOException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import java.io.StringReader;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
 * Class provides method to create a Document object from string source
 * 
 * @author Trifolium Alpestre
 */
public class DocumentFromStringBuilder {
    
    /**
     * 
     * Method creates a Document object from string source
     * 
     * @param xml
     * @return
     * @throws javax.xml.parsers.ParserConfigurationException
     * @throws java.io.IOException
     * @throws org.xml.sax.SAXException
     */
    public Document loadXmlFromString(String xml) throws ParserConfigurationException, IOException, SAXException
    {
     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

     factory.setNamespaceAware(true);
     DocumentBuilder builder = factory.newDocumentBuilder();

     return builder.parse(new InputSource(new StringReader(xml)));
    }


}
