Java tutorial
//package com.java2s; //License from project: Apache License import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.xml.sax.InputSource; public class Main { public static boolean isValidXml(String xml) { try { StringReader reader = new StringReader(xml); DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); db.parse(new InputSource(reader)); } catch (Exception e) { return false; } return true; } }