Simple XML Validator - The Coding Shala
Home >> Programming Questions >> XML Validator In this post, we will are going to implement a Simple XML Validator in the Java language. Simple XML Validator in Java The input is an ASCII string, we have to write a Java program to check if the given String is valid XML or not. For simplicity purposes, the XML string only has content and tags. The output should be a String for whether the text is valid XML or not. If the XML is invalid, output one of the three error strings: 1. "missing closing tag for <start_tag>" 2. "encountered closing tag without matching open tag for </end tag>" 3. "parse error" Example 1: Input: <a>some text</a> Output: valid Example 2: Input: <a> Output: missing closing tag for <a> Approach We can use the stack data structure. Java Program: class Solution { public String validate_xml ( String xml ) { if ( xml == null || xml . isEmpty ()) return "v...