[lxml-dev] Reparenting a node
I have a doc A and a doc B, I'd like to put a node extracted from A in the document B but I always get a ValueError: ValueError: Element is not a child of this node. I didn't find any "setparent" in the API. How can I do this? -- Lawrence, oluyede.org - neropercaso.it "It is difficult to get a man to understand something when his salary depends on not understanding it" - Upton Sinclair
Lawrence Oluyede wrote:
I have a doc A and a doc B, I'd like to put a node extracted from A in the document B but I always get a ValueError:
ValueError: Element is not a child of this node.
Sounds like you're using remove() or index(), no need to do that.
I didn't find any "setparent" in the API.
How can I do this?
try node_in_B.append(node_in_A) See the "Elements are lists" section in the tutorial. Stefan
In order to move a node from one XML document to another using the lxml library, you need to detach the node from its original parent and then append it to the new parent. You can do this by calling the getparent() method to get the parent of the node and then calling the remove() method on the parent to detach the node. After that, you can append the detached node to the new parent by calling the append() method. https://retrobowl.pro/
participants (3)
-
antoniesmith7718@yahoo.com
-
Lawrence Oluyede
-
Stefan Behnel