Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Xerces How to Determine Line Number While Traversing DOM

Reply
Thread Tools

Xerces How to Determine Line Number While Traversing DOM

 
 
Jim Cobban
Guest
Posts: n/a
 
      12-02-2003
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 http://www.velocityreviews.com/forums/(E-Mail Removed)
34 Palomino Dr.
Kanata, ON, CANADA
K2M 1M1
+1-613-592-9438


 
Reply With Quote
 
 
 
 
Philippe Poulard
Guest
Posts: n/a
 
      12-03-2003
Jim Cobban wrote:
> 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 |
-----------------------

 
Reply With Quote
 
 
 
 
Jim Cobban
Guest
Posts: n/a
 
      12-03-2003

"Philippe Poulard" <(E-Mail Removed)> wrote in message
news:bqkbst$c2t$(E-Mail Removed)...
> Jim Cobban wrote:
> > 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()


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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
speed issues traversing the DOM. The Natural Philosopher Javascript 90 12-04-2008 11:47 PM
Traversing the DOM & maintaining node hierarchy matth Javascript 11 02-13-2008 10:05 PM
Removal of element from list while traversing causes the nextelement to be skipped William McBrine Python 23 02-01-2008 05:22 PM
Changing a value for each folder while traversing a file system PipedreamerGrey Python 6 07-28-2006 02:45 PM
Upgrade of Xalan 1.2.2 and Xerces 1.4.4 to Xalan 2.6 and Xerces 2.6.2 cvissy XML 0 11-16-2004 07:06 AM



Advertisments