12.7. Tree Cut-and-Paste

Pyxies provides a Cut method that allows you to cut a piece out of a tree—the cutting is itself an xTree object. The PasteDown and PasteRight methods can be used to insert a tree into another tree. The PasteDown method positions the inserted tree, as the first child of the active node. The PasteRight method positions the inserted tree to the right of the active node.

In the following example, the b element is moved to the left of “Hello” with cut and paste operations.

CD-ROM reference=12017.txt
C>type p15.py """ Move b element to the left of "Hello" using cut and paste operations. """ from pyxie import * import sys t = File2xTree (sys.argv[1]) NormalizeWhiteSpaceSMG(t) t.Down() t.Right() t1 = t.Cut() t.Home() t.PasteDown(t1) ...

Get XML Processing with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.