Removing ":" from namespace in a XML file parsing

I am trying to modify XML file using xml.etree.ElementTree on Python 2.6.6 (due to restrictions) and facing ns0 issue. I looked at this issue and used ET._namespace_map[uri] = prefix as suggested which removed ns0 but the element tags still has the : value. How do we remove it or does it impact the validity of the XML file when we use if for further processing?


<?xml version="1.0" encoding="UTF-8" ?> <Seed xmlns="">     <TagA>         <TagB>B</TagB>         <TagC>c</TagC>     </TagA> </Seed> 


import xml.etree.ElementTree as ET  tree = ET.parse('sample.xml') root = tree.getroot()  try:     ET.register_namespace("","") except AttributeError:     def register_namespace(prefix, uri):         ET._namespace_map[uri] = prefix     register_namespace("","") tree.write('sample.xml') 

Note: I could not use lxml or other xml.etree that is supported only from 2.7 version.

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.