Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

import org.xml.sax.InputSource;

public class Main {
    public static Document parseString(final String xml) {
        try {
            return parseStream(new ByteArrayInputStream(xml.getBytes("utf-8")));
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static Document parseStream(final InputStream xmlis) {
        try {
            return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(xmlis));
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }
}