Java tutorial
//package com.java2s; import java.io.IOException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class Main { public static boolean isXMLWellFormed(String xmlUrl) throws IOException, SAXException, ParserConfigurationException { boolean isXMLValid = false; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = (Document) builder.parse(new InputSource(xmlUrl)); isXMLValid = true; return isXMLValid; } }