cElementTree cannot hold ElementTree instances.
#from elementtree.Ele mentTree import ElementTree, dump # This works
from cElementTree import ElementTree, dump # This does not
from elementtree import ElementInclude
etree = ElementTree(fil e='xml_in.xml') .getroot()
dump(etree)
ElementInclude. include(etree)
dump(etree)
for child in etree.find('./included_root') .findall('./*'):
# Copy the child down to the root
etree.append(ch ild)
# Remove the root/included_root
etree.remove(et ree.find('./included_root') )
dump(etree)
<!--xml_in.xml-->
<root xmlns:xi="http://www.w3.org/2001/XInclude">
<child name="first"/>
<xi:include href="xml_inclu ded.xml"/>
</root>
<!--xml_included.xm l-->
<included_roo t>
<child name="second"/>
<child name="third"/>
</included_root>
Thanks for the help.
Mark
>
can you post a small but self-contained example showing how you got this
error?
can you post a small but self-contained example showing how you got this
error?
</F>
#from elementtree.Ele mentTree import ElementTree, dump # This works
from cElementTree import ElementTree, dump # This does not
from elementtree import ElementInclude
etree = ElementTree(fil e='xml_in.xml') .getroot()
dump(etree)
ElementInclude. include(etree)
dump(etree)
for child in etree.find('./included_root') .findall('./*'):
# Copy the child down to the root
etree.append(ch ild)
# Remove the root/included_root
etree.remove(et ree.find('./included_root') )
dump(etree)
<!--xml_in.xml-->
<root xmlns:xi="http://www.w3.org/2001/XInclude">
<child name="first"/>
<xi:include href="xml_inclu ded.xml"/>
</root>
<!--xml_included.xm l-->
<included_roo t>
<child name="second"/>
<child name="third"/>
</included_root>
Thanks for the help.
Mark