I have an xml-document that looks like this:
All I want to do is change
http://someurl/Oldschema
tohttp://someurl/Newschema
andhttp://someurl/Oldframework
tohttp://someurl/Newframework
and leave the remaining document unchanged.
I'd do a simple textual search-and-replace operation. It's much easier than fiddling with XML nodes. Like this:
with open("input.xml", "r") as infile, open("output.xml", "w") as outfile:
data = infile.read()
data = data.replace("http://someurl/Oldschema", "http://someurl/Newschema")
data = data.replace("http://someurl/Oldframework", "http://someurl/Newframework")
outfile.write(data)
The other question that you were inspired by is about adding a new namespace (and keeping the old ones). But you are trying to modify existing namespace declarations. Creating a new root element and copying the child nodes does not work in this case.
This line:
new_root[:] = root[:]
turns the children of the original root element into children of the new root element. But these child nodes are still associated with the old namespaces. So they have to be modified/recreated too. I guess it might be possible to come up with a reasonable way to do that, but I don't think you need it. Textual search-and-replace is good enough, IMHO.