Changed license to LGPLv3 or later.
[svjatoslav_commons.git] / src / main / java / eu / svjatoslav / commons / data / xml / XmlHelper.java
1 /*
2  * Svjatoslav Commons - shared library of common functionality.
3  * Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 3 of the GNU Lesser General Public License
7  * or later as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.commons.data.xml;
11
12 import java.io.IOException;
13 import java.io.InputStream;
14
15 import javax.xml.parsers.DocumentBuilder;
16 import javax.xml.parsers.DocumentBuilderFactory;
17 import javax.xml.parsers.ParserConfigurationException;
18
19 import org.w3c.dom.Document;
20 import org.xml.sax.SAXException;
21
22 public class XmlHelper {
23
24         public static XmlElement parseXml(final InputStream inputStream)
25                         throws SAXException, IOException, ParserConfigurationException {
26
27                 final DocumentBuilderFactory builderFactory = DocumentBuilderFactory
28                                 .newInstance();
29
30                 final DocumentBuilder builder = builderFactory.newDocumentBuilder();
31
32                 final Document document = builder.parse(inputStream);
33
34                 final XmlElement xmlElement = new XmlElement(
35                                 document.getDocumentElement());
36
37                 return xmlElement;
38         }
39
40 }