14 pythonのxml操作


 
 
#-*-coding:UTF-8-*-
#python xml     
import xml.etree.ElementTree as etree       #ElementTree  python       
tree=etree.parse('feed.xml')    #parse()            ,             
root=tree.getroot()             #     
print root.tag                 #       
print len(root)                #              

for child in root:
    print child
#    
print root.attrib              #         ,     

print root[0]                  #        

#    
print root.findall('c')         #         ,         ,       

print root[0].find('b1')        #          

#  XML
new_feed=etree.Element('e')
print new_feed