Xerces How to Determine Line Number While Traversing DOM

Discussion in 'XML' started by Jim Cobban, Dec 2, 2003.

  1. Jim Cobban

    Jim Cobban Guest

    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
    34 Palomino Dr.
    Kanata, ON, CANADA
    K2M 1M1
    +1-613-592-9438
     
    Jim Cobban, Dec 2, 2003
    #1
    1. Advertising

  2. 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 |
    -----------------------
     
    Philippe Poulard, Dec 3, 2003
    #2
    1. Advertising

  3. Jim Cobban

    Jim Cobban Guest

    "Philippe Poulard" <> wrote in message
    news:bqkbst$c2t$...
    > 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.
     
    Jim Cobban, Dec 3, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PipedreamerGrey
    Replies:
    6
    Views:
    416
    PipedreamerGrey
    Jul 28, 2006
  2. William McBrine
    Replies:
    23
    Views:
    609
    William McBrine
    Feb 1, 2008
  3. Johannes Bauer
    Replies:
    4
    Views:
    426
    Kai-Uwe Bux
    Jan 30, 2009
  4. matth
    Replies:
    11
    Views:
    179
    Evertjan.
    Feb 13, 2008
  5. The Natural Philosopher

    speed issues traversing the DOM.

    The Natural Philosopher, Nov 29, 2008, in forum: Javascript
    Replies:
    90
    Views:
    680
Loading...

Share This Page