0

I can use only Python 2.5 and ElementTree 1.2 I am working on a requirement to parse and read the values of elements from namespace based XML file. I am not keen to use URI's to refer the tag's of the XML in the python code. But I am on to register them once at the start of the code and use them in the subsequent sections.

Please note I tried below approaches they did not work

register_namespace()

namespace = {'abc': 'http://www.example.com'}

Can someone please help me if there is any other way available in Python 2.5 to register the namespaces ?

For Example:

<?xml version = "1.0" encoding = "UTF-8"?>
<cont:contact xmlns:cont = "www.tutorialspoint.com/profile">
 <cont:name>Patil</cont:name>
 <cont:company>XYZ</cont:company>
 <cont:phone>(011) 123-4567</cont:phone>
</cont:contact>

I want to read name from the above xml like this I have many tags in the actual XML I am working on.

If I use URI while referring the xml elements in find() function, code does not look tidier hence I am wondering if there is a way in Python2.5 to register the namespace once and use it everywhere.

In the current setup, I have Python 2.5 only and I have no option of getting it upgraded.

Althaf
  • 21
  • 2
  • 6
  • You failed to post a [mcve], so the examples and general advice in the duplicate links is as good as you can hope to receive. – kjhughes Aug 18 '22 at 12:23
  • I've edited my question to provide more details. Hope it gives the little clear picture of what am I after. – Althaf Aug 18 '22 at 13:37
  • Does your code not work at all or is the problem just that "code does not look tidier"? Python 2.5 is very old. I'd say that your biggest problem is having no option of getting it upgraded. – mzjn Aug 19 '22 at 08:04
  • It is working as expected, But it is just that it does not look tidier.. I understood there is nothing much I can do on it with this version of Python. Thank you for your time. – Althaf Aug 22 '22 at 07:26

0 Answers0