Xerces How to Determine Line Number While Traversing DOM

J

Jim Cobban

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?

--
Jim Cobban (e-mail address removed)
34 Palomino Dr.
Kanata, ON, CANADA
K2M 1M1
+1-613-592-9438
 
P

Philippe Poulard

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()
--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
 
J

Jim Cobban

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

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,006
Latest member
LauraSkx64

Latest Threads

Top