Reading XML using Python minidom and iterating over each node

后端 未结 5 1629
既然无缘
既然无缘 2020-12-08 10:38

I have an XML structure that looks like the following, but on a much larger scale:


    
        
             


        
5条回答
  •  天命终不由人
    2020-12-08 11:18

    Since you always have one text data value per author you can use element.firstChild.data

    dom = parseString(document)
    conferences = dom.getElementsByTagName("conference")
    
    # Each conference here is a node
    for conference in conferences:
        conference_name = conference.getAttribute("name")
        print 
        print conference_name.upper() + " - "
    
        authors = conference.getElementsByTagName("author")
        for author in authors:
            print "  ", author.firstChild.data
        # for
    
        print
    

提交回复
热议问题