How to get line number in sax?


XML & Web services: How to get line number in sax?

  1. How to get line number in sax? (5 messages)

    I am trying to figre out how to get a line number as to where I threw an exception from the endTag method. I am trying to use the Locator interface, but I keep getting -1 for the line number. Any help would be apreciated.

    Marc Boorshtein

    Threaded Messages (5)

  2. How to get line number in sax?[ Go to top ]

    The default SAX parser implementations in some of the JDKs and XML packs had a "performance optimization" of not counting lines, and it allways returned -1 for the line number. The only solution I know of is to switch to another SAX parser implementation (I think the one in JDK1.4 no longer has this "optimization").

  3. How to get line number in sax?[ Go to top ]

    I remember trying it a while ago ...
    Here is some code
    /** Returns a string of the location. */
    private String getLocationString(SAXParseException ex) {
    StringBuffer str = new StringBuffer();

    str.append("] Column[");

    return str.toString();

    } // getLocationString(SAXParseException)
  4. sax tutorial[ Go to top ]

    this page talks about ContentHandler.setDocumentLocator; a callback invoked once before parsing begins. It knows all about the documents location and the parsing position.

    i think the addendum tutorials are excellent:
  5. sax tutorial[ Go to top ]

    Didn't you see Marc allready said he is using a locator? In some SAX implementations, the value returned from the locator for the line number is -1. It doesn't count lines as a performance optimization.

  6. sax tutorial[ Go to top ]

    oh. sorry :$