xml-filter with XMLFilterBase() and XMLGenerator() shuffles attributes
Brian Smith
brian at briansmith.org
Thu Dec 20 16:25:59 EST 2007
> > I want prevent it from shuffling attributes, i.e. preserve original
> > file's attribute order. Is there any ContentHandler.features*
> > responsible for that?
>
> I suspect not. attrs is a dictionary which does not maintain
> order, and XML attributes are unordered to begin with. Is
> there any reason other than aesthetics that you want the
> order preserved? It shouldn't matter to any upstream
> consumer of the filtered XML.
I had the same requirements. I also had the requirement to preserve
namespace prefixes. Luckily, for my application I was able to use the
XML_STRING property to handle my requirements. Otherwise, if you drop
down to using PyExpat (not SAX) then you can do what you want. If you
want to keep using SAX, then you need to use a non-default Python SAX
implementation or use one of the Java SAX parsers that have this option.
BTW, I have never been able to get XMLGenerator to work; it seems really
buggy regarding namespaces. I had to write my own version of it.
- Brian
More information about the Python-list
mailing list