I've got a fairly complex xml config setup with multiple files xincluded. I'm trying to write a tool that allows me to replace certain values programmatically and write the modified file. I lxml.etree.parse() the file then xinclude(). I replace the appropriate text values and want to write the tree back to the filesystem using the original files. I figured out that I can locate the file containing the modified node with something like: ``` cur, top = node, node while cur.base == node.base: top, cur = cur, cur.getparent()
with open(top.base, "wb") as f: f.write(et.tostring(top)) ``` However, any elements that have a different base are still written to that same file. Is there a way I can either write a whole tree such that anything with a different base gets written to the appropriate file and an xinclude added for that file? The only other solution I can think of, is to find any node with a base attribute, replace with with an xinclude and add the node to a list of items to write. _______________________________________________ lxml - The Python XML Toolkit mailing list -- lxml@python.org To unsubscribe send an email to lxml-le...@python.org https://mail.python.org/mailman3/lists/lxml.python.org/ Member address: arch...@mail-archive.com