Monday, April 1, 2013

How to save namespaces of XML in dictoinary in Python and Lxml



I have a XML file with many namespaces:
 xmlns:ser="https://some_address" xmlns:mirror="https://some_mirror_address"/>
    server="some_server_address"/>
    default="some_mirror_address"/>
I am using lxml and python to this type of file. Now, My requirement is, When I parse this XML file I need to store all namespaces in a dictionary like:

nsd = {'ser' : 'https://some_address', 'mirror' : 'https://some_mirror_address'}
 
The intention of this, the namespaces are not predetermined. So When I parse the XML I need to store all the namespaces in a dictionary and then proceed with further activities.
Is this possible to achieve in lxml?

No comments:

Post a Comment