Package: a-pandas-ex-xml2df
#as dataframe#pip install a-pandas-ex-xml2df#### UPDATE 08.12.2022 - xpath / snippetsfroma_pandas_ex_xml2dfimportpd_add_read_xml_files,xml_to_dict,xml_to_dfimportpandasaspdpd_add_read_xml_files()df=pd.Q_Xml2df('https://gist.githubusercontent.com/jasonbaldridge/2597611/raw/c2c6a072c7d018c35aefad6b4739ac75247e5d92/music.xml',add_xpath_and_snippet=True)print(df[1:6].to_string())aa_all_keysaa_valueaa_fileaa_xpathaa_snippet1(artist,0,album,0,description,link)http://en.wikipedia.org/wiki/The_King_of_Limbshttps://gist.githubusercontent.com/jasonbaldridge/2597611/raw/c2c6a072c7d018c35aefad6b4739ac75247e5d92/music.xml//artist[1]/album[1]/description<descriptionlink="http://en.wikipedia.org/wiki/The_King_of_Limbs">2(artist,0,album,0,song,0,length)5:15https://gist.githubusercontent.com/jasonbaldridge/2597611/raw/c2c6a072c7d018c35aefad6b4739ac75247e5d92/music.xml//artist[1]/album[1]/song[1]<songlength="5:15"title="Bloom"/>3(artist,0,album,0,song,0,title)Bloomhttps://gist.githubusercontent.com/jasonbaldridge/2597611/raw/c2c6a072c7d018c35aefad6b4739ac75247e5d92/music.xml//artist[1]/album[1]/song[1]<songlength="5:15"title="Bloom"/>4(artist,0,album,0,song,1,length)4:41https://gist.githubusercontent.com/jasonbaldridge/2597611/raw/c2c6a072c7d018c35aefad6b4739ac75247e5d92/music.xml//artist[1]/album[1]/song[2]<songlength="4:41"title="Morning Mr Magpie"/>5(artist,0,album,0,song,1,title)MorningMrMagpiehttps://gist.githubusercontent.com/jasonbaldridge/2597611/raw/c2c6a072c7d018c35aefad6b4739ac75247e5d92/music.xml//artist[1]/album[1]/song[2]<songlength="4:41"title="Morning Mr Magpie"/>froma_pandas_ex_xml2dfimportpd_add_read_xml_files,xml_to_dict,xml_to_dfimportpandasaspdpd_add_read_xml_files()df=pd.Q_Xml2df('https://gist.githubusercontent.com/jasonbaldridge/2597611/raw/c2c6a072c7d018c35aefad6b4739ac75247e5d92/music.xml')pd.Q_Xml2df('https://gist.githubusercontent.com/jasonbaldridge/2597611/raw/c2c6a072c7d018c35aefad6b4739ac75247e5d92/music.xml')Out[4]:aa_all_keysaa_valuelevel_0level_1level_2level_3level_4level_5level_6artist0album0.0descriptiondescriptionNaN(artist,0,album,0,description,description)\n\tTheKingofLimbsistheeighthstudioalb...linkNaN(artist,0,album,0,description,link)http://en.wikipedia.org/wiki/The_King_of_Limbssong0length(artist,0,album,0,song,0,length)5:15title(artist,0,album,0,song,0,title)Bloom1length(artist,0,album,0,song,1,length)4:41......1album1.0song9title(artist,1,album,1,song,9,title)MagicDoors10length(artist,1,album,1,song,10,length)5:45title(artist,1,album,1,song,10,title)ThreadstitleNaNNaN(artist,1,album,1,title)ThirdnameNaNNaNNaNNaN(artist,1,name)Portishead[98rowsx2columns]#dataframe and dictxmlfileorstrin11=r"C:\Users\Gamer\Documents\Downloads\00000001_untouched.xml"link='https://gist.githubusercontent.com/jasonbaldridge/2597611/raw/c2c6a072c7d018c35aefad6b4739ac75247e5d92/music.xml'uu1=xml_to_dict(xmlfileorstrin11)uu11=xml_to_df(xmlfileorstrin11)withopen(xmlfileorstrin11,encoding='utf-8')asf:xmlfileorstring=f.read()uu2=xml_to_dict(xmlfileorstrin11)uu22=xml_to_df(xmlfileorstrin11)uu3=xml_to_dict(link)uu33=xml_to_df(link)uu1Out[12]:{'folder':'data','filename':'00000001_untouched.png','path':None,'source':{'database':'Unknown'},'size':{'width':1920,'height':1080,'depth':3},'segmented':0,'object':[{'name':'search_bar','pose':'Unspecified','truncated':0,'occluded':0,'difficult':0,'bndbox':{'xmin':753,'ymin':8,'xmax':1172,'ymax':52}},{'name':'home_text','pose':'Unspecified','truncated':0,'occluded':0,'difficult':0,'bndbox':{'xmin':42,'ymin':5,'xmax':158,'ymax':55}},{'name':'add_friends','pose':'Unspecified','truncated':0,'occluded':0,'difficult':0,'bndbox':{'xmin':44,'ymin':185,'xmax':152,'ymax':310}}]}uu11Out[14]:aa_all_keysaa_valuelevel_0level_1level_2level_3filenameNaNNaNNaN(filename,)00000001_untouched.pngfolderNaNNaNNaN(folder,)dataobject0bndboxxmax(object,0,bndbox,xmax)1172xmin(object,0,bndbox,xmin)753ymax(object,0,bndbox,ymax)52ymin(object,0,bndbox,ymin)8difficultNaN(object,0,difficult)0nameNaN(object,0,name)search_baroccludedNaN(object,0,occluded)0poseNaN(object,0,pose)UnspecifiedtruncatedNaN(object,0,truncated)01bndboxxmax(object,1,bndbox,xmax)158xmin(object,1,bndbox,xmin)42ymax(object,1,bndbox,ymax)55ymin(object,1,bndbox,ymin)5difficultNaN(object,1,difficult)0nameNaN(object,1,name)home_textoccludedNaN(object,1,occluded)0poseNaN(object,1,pose)UnspecifiedtruncatedNaN(object,1,truncated)02bndboxxmax(object,2,bndbox,xmax)152xmin(object,2,bndbox,xmin)44ymax(object,2,bndbox,ymax)310ymin(object,2,bndbox,ymin)185difficultNaN(object,2,difficult)0nameNaN(object,2,name)add_friendsoccludedNaN(object,2,occluded)0poseNaN(object,2,pose)UnspecifiedtruncatedNaN(object,2,truncated)0pathNaNNaNNaN(path,)NonesegmentedNaNNaNNaN(segmented,)0sizedepthNaNNaN(size,depth)3heightNaNNaN(size,height)1080widthNaNNaN(size,width)1920sourcedatabaseNaNNaN(source,database)Unknown