Getting lxml tag attributes with namespaces

acrolislory

New Member
My XML looks like:\[code\]...<termEntry id="c1"> <langSet xml:lang="de"> ...\[/code\]And i have the code:\[code\]from lxml import etree...for term_entry in root.iterfind('.//termEntry'): print term_entry.attrib['id'] print term_entry.nsmap for lang_set in term_entry.iterfind('langSet'): print lang_set.nsmap print lang_set.attrib for some_stuff in lang_set.iterfind('some_stuff'): ...\[/code\]I get the empty nsmap dict, and my attrib dict looks like \[code\]{'{http://www.w3.org/XML/1998/namespace}lang': 'en'}\[/code\]The file may not contain \[code\]xml:\[/code\] in namespace, or it may have a different namespace. How can i know what namespace used in the tag declaration? In fact, i just need to get a \[code\]lang\[/code\] attribute, i don't care what namespace was used. I don't want use any crappy trash like \[code\]lang_set.attrib.values()[0]\[/code\] or other lookups of a field with the known name.
 
Back
Top