Using cElementTree and elementtree.ElementInclude

Discussion in 'Python' started by Mark E. Smith, Oct 23, 2006.

  1. > cElementTree cannot hold ElementTree instances.
    >
    > can you post a small but self-contained example showing how you got this
    > error?


    > </F>




    #from elementtree.ElementTree import ElementTree, dump # This works
    from cElementTree import ElementTree, dump # This does not
    from elementtree import ElementInclude

    etree = ElementTree(file='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(child)
    # Remove the root/included_root
    etree.remove(etree.find('./included_root'))
    dump(etree)


    <!--xml_in.xml-->
    <root xmlns:xi="http://www.w3.org/2001/XInclude">
    <child name="first"/>
    <xi:include href="xml_included.xml"/>
    </root>

    <!--xml_included.xml-->
    <included_root>
    <child name="second"/>
    <child name="third"/>
    </included_root>


    Thanks for the help.
    Mark
     
    Mark E. Smith, Oct 23, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    0
    Views:
    318
  2. Mark
    Replies:
    0
    Views:
    311
  3. Michael Becker
    Replies:
    1
    Views:
    267
    Stefan Behnel
    Mar 23, 2008
  4. Kee Nethery
    Replies:
    12
    Views:
    2,168
    Stefan Behnel
    Jun 27, 2009
  5. Ben Temperton

    When to clear elements using cElementTree

    Ben Temperton, Oct 19, 2012, in forum: Python
    Replies:
    1
    Views:
    191
    Ben Temperton
    Oct 19, 2012
Loading...

Share This Page