JAVA XML

JavaXml Projects

JavaXml Project 1

JavaXml Examples

JavaXml EXAMPLE

adplus-dvertising
XML checker Error and locater
Previous Home Next

In this program, we will be learn to check the error and locate them by line and by column number in our XML document using the DOM Application programming interface. The XML document follows some rules to check its.

Here is the XML File: Student_Detail1.xml

<?xml version = "1.0" ?>
<Student_Detail1>
<Student>
<stu_Id> s-001 </stu_Id>
<stu_Name> ajay </stu_Name>
<stu_E-mail> ajay1@yahoo.com </stu_E-mail>
</Student>
</Student_Detail1>

Here is the Java File: Finderror.java

package r4r;
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
public class finderror {
	public static void main(String[] arg){
		try {
		BufferedReader br = new BufferedReader(new
		InputStreamReader(System.in));
		System.out.print("Enter the File name: ");
		String str = br.readLine();
		File file = new File(str);
		if(file.exists()){
		DocumentBuilderFactory fact = 
		DocumentBuilderFactory.newInstance();
		DocumentBuilder build = fact.newDocumentBuilder();
		Document docu = build.parse(str);
		System.out.println(str + " well");
		}
		else{
		System.out.print("File not found!");
		}
		}[an error occurred while processing this directive]
		catch (SAXParseException e) {
		System.out.println("type" + ": " + e.getMessage()+"\n");
		System.out.println("Line " + e.getLineNumber() + " Column "
		+ e.getColumnNumber());
		}
		catch (SAXException e) {
		System.err.println(e);
		System.exit(1);
		}
		catch (ParserConfigurationException e) {
		System.err.println(e);
		System.exit(1);
		}
		catch (IOException e) {
		System.err.println(e);
		System.exit(1);
		}
		}
}

Previous Home Next