[lxml-dev] Processing instruction roundtrip (again)
Hi, i've got a problem with Processing Instructions (2.0alpha5, Python2.4):
obj = lxml.objectify.XML('<a/><?foo:bar blurb ?>') lxml.etree.tostring(obj) '<a/>' obj = lxml.objectify.XML('<a><?foo:bar blurb ?></a>') lxml.etree.tostring(obj) '<a><?foo:bar blurb ?></a>'
So a PI not contained in the root node gets lost. Any way to fix this? -- Christian Zagrodnick gocept gmbh & co. kg · forsterstrasse 29 · 06112 halle/saale www.gocept.com · fon. +49 345 12298894 · fax. +49 345 12298891
Christian Zagrodnick wrote:
obj = lxml.objectify.XML('<a/><?foo:bar blurb ?>') lxml.etree.tostring(obj) '<a/>'
You are requesting a serialisation of the Element, so that's the expected result. This should work: etree.tostring(etree.ElementTree(obj)) or: etree.tostring(obj.getroottree()) Stefan
On 08.12.2007, at 16:17, Stefan Behnel wrote:
Christian Zagrodnick wrote:
obj = lxml.objectify.XML('<a/><?foo:bar blurb ?>') lxml.etree.tostring(obj) '<a/>'
You are requesting a serialisation of the Element, so that's the expected result.
This should work:
etree.tostring(etree.ElementTree(obj))
or:
etree.tostring(obj.getroottree())
Ah yes. This way it works. Rather strange that fromstring/tostring is not symetric. But from the usesage patterns it probably makes sense. I'm probably going to serialse the roottree whenever a node doesn't have a parent. But thanks for the hint :) -- Christian Zagrodnick gocept gmbh & co. kg · forsterstrasse 29 · 06112 halle/saale www.gocept.com · fon. +49 345 12298894 · fax. +49 345 12298891
participants (2)
-
Christian Zagrodnick
-
Stefan Behnel