Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.Reader;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.xml.sax.InputSource;

public class Main {
    static DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

    public static boolean isValidXML(String xml) {
        try {
            DocumentBuilder builder = dbf.newDocumentBuilder();
            Reader reader = null;
            try {
                reader = new StringReader(xml);
                builder.parse(new InputSource(reader));
            } finally {
                if (reader != null) {
                    reader.close();
                }
            }
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}