0

From the below XML, I want to remove the start and end tag for <root> so that <INVOKE> becomes the top level node. Also the <item> tag is to be removed in such a way that <DNAME>,<PEMAIL> and <PHONE> becomes the child of <PER>

I found the solution for deleting the child nodes from https://docs.python.org/3/library/xml.etree.elementtree.html. But the child node has to be deleted in such a way that the grand-child becomes the child node.

<root>
    <Invoke>
        <Set>
            <INT>
                <co>1</co>
                <ti>2</ti>
                <WOSTATUS>11</WSTATUS>
                <PER>
                    <item>
                        <DNAME>12</DNAME>
                        <PEMAIL>13</PEMAIL>
                        <PPHONE>14</PPHONE>
                    </item>
                </PER>
            </INT>
        </Set>
    </Invoke>
</root>
Stan11
  • 274
  • 3
  • 11
  • Possible duplicate of [python xml.etree - remove node but keep children (assign children to grandparents)](https://stackoverflow.com/questions/38021298/python-xml-etree-remove-node-but-keep-children-assign-children-to-grandparent) – AMC Nov 08 '19 at 06:26
  • Thank You ..The 2nd part of the question is cleared. Could u please help me in resolving the 1st – Stan11 Nov 08 '19 at 07:06
  • The first part being removing `` so that `` is the top level tag? – AMC Nov 08 '19 at 07:08
  • Yes that part only – Stan11 Nov 08 '19 at 07:10
  • I’m confused, isn’t it the same thing as the second part? – AMC Nov 08 '19 at 07:13
  • i dont think so because for example if i consider the node to be deleted as B, its parent as A and the grandchild as C, then in the link u mentioned they are deleting B and appending C as the child of A. But here is the one to be deleted that is B, we have a C also in the form of , i dont have an A here right? – Stan11 Nov 08 '19 at 07:17
  • "How to remove root element from xml file using python?": https://stackoverflow.com/q/34084658/407651 – mzjn Nov 08 '19 at 07:24
  • yes thank you soo much – Stan11 Nov 08 '19 at 07:49

0 Answers0