Fastest way to extract used namespaces from a piece of XML?

Martin von Loewis loewis at informatik.hu-berlin.de
Sat Jun 16 14:59:31 EDT 2001


"Thomas Weholt" <thomas at cintra.no> writes:

> I need the fastest code available for extracting all namespaces used in a
> piece of xml. I got this code for doing this, but it's slow as hell. Any
> clues?

Using xml.parsers.expat directly is certainly faster; just set the
StartElement handler, and no other handler.

If you have PyXML, using xml.parsers.sgmlop might be even faster. You
will have to do the namespace processing yourself, i.e. by looking at
attributes that start with xmlns.

Regards,
Martin



More information about the Python-list mailing list