[lxml-dev] An lxml tree inside a lxml tree.

John Lovell jlovell at esd189.org
Thu Mar 20 19:27:16 CET 2008


Okay, I came up with some sample code to illustrate my problem and the
behavior shows up without included one tree inside another.
 

Code:
 
from lxml import etree
from StringIO import StringIO
 
xml = """<root>
  <child1/>
  <child2/>
  <child3/>
</root>
"""
 
# It doesn't matter which one of these I use.
root = etree.fromstring(xml)
#root = etree.parse(StringIO(xml)).getroot()
 
print root.tag
 
print ""
 
print etree.tostring(root, pretty_print=False)
 
 
Output:
 
root
 
<root>
  <child1/>
  <child2/>
  <child3/>
</root>

 
Thanks,
 
John

________________________________

From: lxml-dev-bounces at codespeak.net
[mailto:lxml-dev-bounces at codespeak.net] On Behalf Of John Lovell
Sent: Wednesday, March 19, 2008 10:38 AM
To: lxml-dev at codespeak.net
Subject: [lxml-dev] An lxml tree inside a lxml tree.


I am appending one lxml tree's root element into another lxml tree.
Everything seems to work fine until I serialize (a.k.a. tostring) the
containing tree.  At which point everything is serialized, however the
appended subtree ignores the given pretty_print setting.  Is there a way
to have the included tree be just more elements in the bigger tree?  Or,
do I misunderstand the problem.
 
Note that I haven't updated to lxml 2 yet.
 
python:            2.5.1
lxml.etree:        (1, 3, 3, 0)
libxml used:       (2, 6, 30)
libxml compiled:   (2, 6, 29)
libxslt used:      (1, 1, 21)
libxslt compiled:  (1, 1, 21)

Thanks,
 
John W. Lovell
Web Applications Engineer
Northwest Educational Service District
1601 R Avenue
Anacortes, WA 98221
 
www.esd189.org <http://www.esd189.org/> 
Together We Can ...
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codespeak.net/pipermail/lxml-dev/attachments/20080320/60d04e5b/attachment-0001.htm 


More information about the lxml-dev mailing list