Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.ByteArrayInputStream;
import java.io.InputStream;

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

public class Main {

    public static boolean validateXml(String xml) {
        boolean flag = true;
        if (xml == null) {
            flag = false;
        } else {
            InputStream is = new ByteArrayInputStream(xml.getBytes());
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            try {
                DocumentBuilder builder = dbf.newDocumentBuilder();
                builder.parse(is);
            } catch (Exception e) {
                flag = false;
            }
        }
        return flag;
    }
}