Connecting Tech Pros Worldwide Help | Site Map

Xerces How to Determine Line Number While Traversing DOM

  #1  
Old July 20th, 2005, 07:35 AM
Jim Cobban
Guest
 
Posts: n/a
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 jcobban@magma.ca
34 Palomino Dr.
Kanata, ON, CANADA
K2M 1M1
+1-613-592-9438


  #2  
Old July 20th, 2005, 07:35 AM
Philippe Poulard
Guest
 
Posts: n/a

re: Xerces How to Determine Line Number While Traversing DOM


Jim Cobban wrote:[color=blue]
> 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?
>[/color]

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 |
-----------------------

  #3  
Old July 20th, 2005, 07:35 AM
Jim Cobban
Guest
 
Posts: n/a

re: Xerces How to Determine Line Number While Traversing DOM



"Philippe Poulard" <Philippe.PoulardNO@SPAMsophia.inria.fr> wrote in message
news:bqkbst$c2t$1@news-sop.inria.fr...[color=blue]
> Jim Cobban wrote:[color=green]
> > I am using Xerces to read an XML file and load it into a DOM so I can[/color][/color]
update[color=blue][color=green]
> > it and subsequently serialize the updated DOM.
> >
> > The problem I have is that as I traverse the DOM I would like to inform[/color][/color]
the[color=blue][color=green]
> > user of exceptional conditions in the file. However I cannot find any[/color][/color]
way[color=blue][color=green]
> > while doing a DOM traversal to determine the line number that a[/color][/color]
particular[color=blue][color=green]
> > Node occurs on, except to count all of the new-line characters which[/color][/color]
occur[color=blue][color=green]
> > in Text Nodes.
> >
> > Am I missing something?
> >[/color]
>
> 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()[/color]

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.


Closed Thread