Pergunta

Yikes, I can't seem to turn on namespace mode and get my contentHandler's startElementNS and endElementNS called. Instead it is still calling startElement and endElement. Here's how I'm setting it up:

source = open(sourceFileName)
xml_parser = xml.sax.make_parser()
handler = MyContentHandler()
xml_parser.setContentHandler(handler)
xml_parser.setFeature(xml.sax.handler.feature_namespaces, True)
xml.sax.parse(source, handler)

How do I turn on namepace mode so it calls startElementNS etc?

Foi útil?

Solução

The last line (xml.sax.parse(source, handler)) creates a new parser. You are not using the xml_parser object for which you have set up namespace mode.

It should work if you change this line to

xml_parser.parse(source)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top