Xerces How to Determine Line Number While Traversing DOM

Jim Cobban

Usenet Archive
Joined
Sep 4, 2002
Messages
45
Reaction score
0
I am using Xerces to read an XML file and load it into a DOM so I can update it and subsequently serialize the updated DOM.

The problem I have is that as I traverse the DOM I would like to inform the user of exceptional conditions in the file. However I cannot find any way while doing a DOM traversal to determine the line number that a particular Node occurs on, except to count all of the new-line characters which occur in Text Nodes.

Am I missing something?
 

Philippe Poulard

Usenet Archive
Joined
Dec 20, 2001
Messages
412
Reaction score
0
Jim said:
I am using Xerces to read an XML file and load it into a DOM so I can update it and subsequently serialize the updated DOM.

The problem I have is that as I traverse the DOM I would like to inform the user of exceptional conditions in the file. However I cannot find any way while doing a DOM traversal to determine the line number that a particular Node occurs on, except to count all of the new-line characters which occur in Text Nodes.

Am I missing something?

hi,

plug an error handler to your parser like this :
myDOMParser.setErrorHandler(myErrorHandler);
when an error occurred, the appropriate method will be called (see org.xml.sax.ErrorHandler) with an instance of org.xml.sax.SAXParseException that have the expected methods getColumnNumber and getLineNumber
 

Jim Cobban

Usenet Archive
Joined
Sep 4, 2002
Messages
45
Reaction score
0
Philippe Poulard said:
hi,

plug an error handler to your parser like this :
myDOMParser.setErrorHandler(myErrorHandler);
when an error occurred, the appropriate method will be called (see org.xml.sax.ErrorHandler) with an instance of org.xml.sax.SAXParseException that have the expected methods getColumnNumber and getLineNumber

Thank you. That is useful to know. However the errors in question are not in the syntax of the XML but rather in the semantics. These are therefore not errors which Xerces can detect for itself, even given an appropriate DTD. That is why I would like to be able to determine the line number while traversing the DOM.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top