I have an xpath for a node in an xml file which does not yet exist, and want to use it to generate the node in question. I’ve started work on a function to do this but was wondering if there’s an existing library which can do it and save me some time? I’m currently working with pyxml but am considering porting it to ElementTree. So to clarify I want :
root/foo/bar
to produce:
<root>
<foo>
<bar>
</bar>
</foo>
</root>
My suspicion is that the behaviour of such a function is not well enough defined for the general case for anyone to have bothered but thought I’d throw it out there just in case. I have a DTD for the file as well if that would help.
Didn’t find anything ready,
but it should be more or less straightforward using ElementTree (or even another xml library – it is just that I am more acquainted with ElementTree).
The snippet bellow seems to work for the limited subset of xpath that is needed for it: