Connecting Tech Pros Worldwide Help | Site Map

Xerces How to Determine Line Number While Traversing DOM

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 06:35 AM
Jim Cobban
Guest
 
Posts: n/a
Default Xerces How to Determine Line Number While Traversing DOM

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, 06:35 AM
Philippe Poulard
Guest
 
Posts: n/a
Default 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, 06:35 AM
Jim Cobban
Guest
 
Posts: n/a
Default 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.


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.