You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Nadav Aharoni <na...@elad.co.il> on 2000/09/12 09:27:56 UTC

element location in files with SAX parsing

I would like to know where in a file an element is.
The SAX parser sends me a pointer to a Locator, and that locator tells me
the line and column of any event.

But, I want to know the exact byte offset from the beginning of the file.

It seems like the SAX API does not support this and that I would have to go
into the code to make the changes that I need.

Before I do this, maybe someone has a clue?

Thanks,
Nadav Aharoni


Re: element location in files with SAX parsing

Posted by Dean Roddey <dr...@charmedquark.com>.
element location in files with SAX parsingThere is a mechanism to do this, but you can't do it via SAX. The XMLScanner object which underlies any parser has this information, if it has been enabled for a particular platform and the specific transcoder that is being used. You can ask it, after you get each callback, where it started at in the file. Since it depends on the ability of the transcoder to provide the information needed, and because it adds a lot of overhead that most people don't want, its not always enabled. Each transcoder system (of which Xerces supports multiples) indicates to the scanner whether it supports this or not.

The method in questoin is XMLScanner::getSrcOffset(). You cannot get to the scanner from the SAXParser, because there isn't a method to access it. The simplest change would be to add a getter to SAXParser that gives you access to its fScanner member. Once you have access to that, when you get each callback, ask the scanne for the byte offset.

--------------------------
Dean Roddey
The CIDLib C++ Frameworks
Charmed Quark Software
droddey@charmedquark.com
http://www.charmedquark.com

"It takes two buttocks to make friction"
    - African Proverb


  ----- Original Message ----- 
  From: Nadav Aharoni 
  To: 'xerces-c-dev@xml.apache.org' 
  Sent: Tuesday, September 12, 2000 12:27 AM
  Subject: element location in files with SAX parsing


  I would like to know where in a file an element is. 
  The SAX parser sends me a pointer to a Locator, and that locator tells me the line and column of any event. 

  But, I want to know the exact byte offset from the beginning of the file. 

  It seems like the SAX API does not support this and that I would have to go into the code to make the changes that I need.

  Before I do this, maybe someone has a clue? 

  Thanks, 
  Nadav Aharoni