Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to find line number of missing tag in an XML using Java XML Parser.

807603Dec 5 2007 — edited Dec 5 2007
I tried to parse an xml file with 39172 lines.

In that one XML tag was mismatching so i am getting error as,

[Fatal Error] BEFORE-AFTER.etest.XMLOUT.isbu-view6.cisco.com.20071130111406.1729
:39172:1: **XML document structures must start and end within the same entity.**

line numer 74

I am trying to figure out on which line of the XML file i am getting error.
I need to correct that particular line.
Is there any way,where i can debug or print the line number up to which it has parsed correctly and on which line the file got broken(failed parsing).

I was using ,

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;

How to change my code to see the line number.Currently the line number that is displayed is not returning the code broken line number,but it is priniting some other line number.
DocumentBuilderFactory factory = DocumentBuilderFactory
					.newInstance();
			factory.setIgnoringComments(true);
			// Get a document builder from the factory.
			DocumentBuilder builder = factory.newDocumentBuilder();

			log.debug("FILE FOR PARSER:" + file);
			//  the input file.
			try
			{
			    doc = builder.parse(file);
		    }catch(SAXException e)
		    { 
			    //System.out.println("Error in Parsing" + e.getStackTrace());
			    Throwable marker = new Throwable();
			    StackTraceElement[] stack = marker.getStackTrace();
			    System.out.println("line numer"+stack[0].getLineNumber());
			}
Thanks,
Srins.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 2 2008
Added on Dec 5 2007
3 comments
1,078 views