[XML-SIG] how to obtain Byte offset from the Locator...

Lars Marius Garshol larsga@garshol.priv.no
07 May 2000 13:41:59 +0200


* Greg Wolff
|
| I've a question for this list about obtaining location information
| during an event call back to the document handler.  I'm writing my first
| Python xml script and having a good time with it.  (This C++ dude thinks
| Python is great...)  But, I can't see how to obtain the byte offset from
| the locator.

There is no way to do that with the Locator.

I plan to add SAX 2.0 properties for the byte offset to the expat and
xmlproc drivers, since both support this functionality, but at the
moment there is no standard way to do this.
 
For speed of access the value of the property should probably be a
function (really a method tied to an object).

BTW, I've been wondering what namespace to use for this. Should we
define common properties/features in the http://www.python.org/
namespace, or should I use my own garshol.priv.no?

| I need the information for search indices that I'm building and would
| rather build the code in Python than C++.

If you _know_ that you are using the expat driver you can look at the
drv_pyexpat.py code and see how to find a reference to the expat
Parser object and try to get the information from there. Not really
the recommended way to do it, but it should work.

--Lars M.