kumarswamy_10 0 Newbie Poster

I am updating an xml file and want to preserve multiple namespaces with same URI but different anchor tag using ET.register_namespace

Following code is what I've tried :

<code>

ET.register_namespace('', "http://oval.mitre.org/XMLSchema/oval-definitions-5")
ET.register_namespace('', "http://oval.mitre.org/XMLSchema/oval-definitions-5#windows")
ET.register_namespace('', "http://oval.mitre.org/XMLSchema/oval-definitions-5#independent")


ns = "{http://oval.mitre.org/XMLSchema/oval-definitions-5}"
f = open ("def_ex.xml","ra")
tree = ET.parse(f)
root = tree.getroot()

for defn in root.iter('%stag' %ns): 
    if "patch" in defn.get("class"): #pick id attrib where class attrib is "patch"
       print defn.get("id")       
       mirr_def = copy.deepcopy(defn)
       defn.append(mirr_def)
       tree.write("def_ex.xml")
       exit()

</code>

But the problem is third namespace is overwriting one and two as shown in following output of the code:
<code>

<ns0:tag>
.......
.......
</ns0:tag>

<ns1:tag1>
........
........
</ns1:tag1>

<tag2>
......
......
</tag2>

</code>

My final question how to preserve all namespaces without overwriting each other when there are different "anchor tag"s with same URI ?