[lxml-dev] greetings, and another bug...
Stefan Behnel
stefan_ml at behnel.de
Tue Apr 17 18:02:20 CEST 2007
Hi,
thanks for the reports. A quick shot on the easy one:
Jim Rees wrote:
> emptynode = ET.Element("Empty")
> emptynode2 = ET.Element("Empty")
> emptynode2.text = ''
>
> print "An empty node with unset text outputs as", ET.tostring(emptynode)
> print "That string parses back in with text set to", str(ET.fromstring(ET.tostring(emptynode)).text)
> print
>
> print "An empty node with text set to the empty string outputs as", ET.tostring(emptynode2)
> print "That string parses back in with text set to", str(ET.fromstring(ET.tostring(emptynode2)).text)
> print "... and re-outputs as", ET.tostring(ET.fromstring(ET.tostring(emptynode2)))
On my side, this writes:
> An empty node with unset text outputs as <Empty/>
I like that.
> That string parses back in with text set to None
Nice.
> An empty node with text set to the empty string outputs as <Empty></Empty>
Cool.
> That string parses back in with text set to None
Not really a bug as XML does not distinguish between <Empty/> and
<Empty></Empty>, so technically, this is ok.
> ... and re-outputs as <Empty/>
As expected.
I'm pretty far from calling this a bug. I'd rather see it as a nice feature of
lxml that it tries to map the empty Python string to something meaningful. I
believe, if you want to make a text empty, you're well off with setting it to
None. So, if you rather pass the empty string, there's likely a reason for it.
Stefan
More information about the lxml-dev
mailing list