I have a huge xml file (1 Gig). I want to move some of the elements (entrys) to another file with the same header and specifications.
Let\'s say the original file co
I often grab a namespace to make an alias for it like this:
someXML = lxml.etree.XML(someString)
if ns is None:
ns = {"m": someXML.tag.split("}")[0][1:]}
someid = someXML.xpath('.//m:ImportantThing//m:ID', namespaces=ns)
You could do something similar to grab the namespace in order to make a regex that will clean it up after using tostring.
Or you could clean up the input string. Find the first space, check if it is followed by xmlns, if yes, delete the whole xmlns bit up to the next space, if no delete the space. Repeat until there are no more spaces or xmlns declarations. But don't go past the first >.