elementtree and entities
Daniel Nogradi
nogradi at gmail.com
Sun May 13 13:00:18 EDT 2007
> > How does one prevent elementtree converting & to & (and similarly
> > for other entities)?
> >
> >>>> from xml.etree import ElementTree as et
> >>>> x = et.Element( 'test' )
> >>>> x.text = '&'
> >>>> et.tostring( x )
> > '<test>&</test>'
> >
> > Sometimes I would like to have the output '<test>&</test>'
> >
>
> elementtree is for processing xml. If you want to output something which
> isn't xml then you'll have to use a different library or mess about with
> the xml after it has been generated:
>
> et.tostring(x).replace('&', '&')
>
> does what you want, but you won't be able to parse it again with anything
> which expects xml.
Thanks for the reply, I'll just live with replace then.
More information about the Python-list
mailing list