XML namespaces and xmllib

Russell Turpin noone at do.not.use
Fri May 26 14:37:23 EDT 2000


Ian Oeschger wrote:
> I don't seem to be able to turn off the namespacing support 
> in xmllib so I can just get the unnamespaced elements and 
> attributes.

It looks to me that the author may not have anticipated 
the desire to handle XML without namespace information. 
What I did was a bit of a kluge, but it works ..

Instead using the elements array, override the methods
unknown_starttag() and unknown_endtag(). These will get
called on every tag. Your methods will need to interpret
the tags. Inside these methods, split the tag argument
on whitespace, and the last piece is the tag proper. The 
first piece, if present, is the namespace.

BTW, the entitydefs that comes with xmllib is terribly
meager, and will cause the parser to choke on a wide 
range of standard characters, such as the British pound
sign. I override the constructor and use htmlentitydefs
to create better entitydefs data.

Good luck!

xml-ing-ly yrs,
Russell



More information about the Python-list mailing list