Python Minidom XML parsing interchangable upper and lower case node names -


hoping here. writing small script pull info data file. following start of xml...its quite big.

<?xml version="1.0" encoding="iso-8859-1"?> <flatnet version="1" id="{014852f8-3010-4a5f-8215-8f47b000ea60}" sch="vbt-mbb-1.4.scs"> <partnumbers> <partnumber name="pn_lib_name" version="1"> <properties ver="1"> <a key="partname" value="part_name"/> <a key="altpartref" value="part_ref"/> 

my problem in of files need parse, node capitalized , in lower case. how node name (either "a" or "a") variable can use function?

else stuck changing manually every time want parse new file depending on file contains.

thanks heaps in advance!

you either have have 2 nodelists , work them individually

a1 = doc.getelementsbytagname('a') a2 = doc.getelementsbytagname('a')  #do stuff a1 , a2 

or normalize tags along lines of this:

>>> import xml.dom.minidom minidom >>> xml = minidom.parsestring('<root><head>hi!</head><body>text<a>blah</a><a>blahblah</a></body></root>') >>> allels = xml.getelementsbytagname('*') >>> in allels:     if i.localname.lower() == 'a':         print i.toxml()   <a>blah</a> <a>blahblah</a> 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -