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


i have xml file many namespaces:

<root xmlns:ser="https://some_address" xmlns:mirror="https://some_mirror_address">    <ser:use server="some_server_address"/>    <mirror:use default="some_mirror_address"/> </root> 

i using lxml , python parse type of file. now, requirement is, when parse xml file need store namespaces in dictionary like:

nsd = {'ser' : 'https://some_address', 'mirror' : 'https://some_mirror_address'} 

the intention of this, namespaces not predetermined. when parse xml need store namespaces in dictionary , proceed further activities.

is possible achieve in lxml?

assuming you're using etree api, given element, can access nsmap property. holds dictionary you're looking for.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -