[XML-SIG] Locating my document locator

Jed Parsons jedp at ilm.com
Wed Jan 26 02:23:19 CET 2005


I'm having trouble locating my document locator.

For me, the following asks, "Dude, where's my Locator?"

    class FooHandler(xml.sax.ContentHandler):
        def __init__(self):
            self.locator = None
            pass

        def setDocumentLocator(self, locator):
            self.locator = locator

        def startDocument(self):
            if self.locator is None:
                raise RuntimeError("Dude, where's my Locator?")

        def characters(self, text):
            line = self.locator.getLineNumber()
            col = self.locator.getColumnNumber()
            print line,',',col, ':', text

    parser = xml.sax.make_parser()
    handler = FooHandler()
    parser.setContentHandler(handler)
    parser.parse('/path/to/some/file.xml')

That snippet based on http://www.xml.com/pub/a/2004/11/24/py-xml.html, which
taunts me with the assertion that, "Every SAX driver I know of that comes with
Python or on PyXML supports locators." 

I know there's a locator there somewhere, because when my xml is broken, the
parser is quick to let me know where :)

Any suggestions much appreciated!

Cheers,

Jed

-- 
Jed Parsons       Industrial Light + Magic  (415) 448-2974 
	     
grep(do{for(ord){(!$_&&print"$s\n")||(($O+=(($_-1)%6+1)and
grep(vec($s,$O++,1)=1,1..int(($_-6*6-1)/6))))}},(split(//,
"++,++2-27,280,481=1-7.1++2,800+++2,8310/1+4131+1++2,80\0.  What!?"))); 



More information about the XML-SIG mailing list