355ec2cc520693aee9eb10afd39889b37e09f94a
[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-2013, 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 2 of the GNU General Public License
7  * as published by the Free Software Foundation.
8  */
9 package eu.svjatoslav.commons.data.xml;
10
11 import java.io.IOException;
12 import java.io.InputStream;
13
14 import javax.xml.parsers.DocumentBuilder;
15 import javax.xml.parsers.DocumentBuilderFactory;
16 import javax.xml.parsers.ParserConfigurationException;
17
18 import org.w3c.dom.Document;
19 import org.xml.sax.SAXException;
20
21 public class XmlHelper {
22
23         public static XmlElement parseXml(final InputStream inputStream)
24                         throws SAXException, IOException, ParserConfigurationException {
25
26                 final DocumentBuilderFactory builderFactory = DocumentBuilderFactory
27                                 .newInstance();
28
29                 final DocumentBuilder builder = builderFactory.newDocumentBuilder();
30
31                 final Document document = builder.parse(inputStream);
32
33                 final XmlElement xmlElement = new XmlElement(
34                                 document.getDocumentElement());
35
36                 return xmlElement;
37         }
38
39 }