2015. 3. 6. 02:00
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

from xml.dom.minidom import parse
import xml.dom.minidom

#open XML document using minidom parser
DOMTree=xml.dom.minidom.parse("movie.xml")
collection=DOMTree.documentElement
if collection.hasAttribute("shelf"):
    print("Root element : %s"%collection.getAttribute("shelf"))

#get all the movies in the collection
movies=collection.getElementsByTagName("movie")

#print detail of each movie
for movie in movies:
    print ("*****Movie*****")
    if movie.hasAttribute("title"):
        print ("Title: %s"%movie.getAttribute("title"))

    type=movie.getElementsByTagName('type')[0]
    print ("Type: %s" %type.childNodes[0].data)
   
    format=movie.getElementsByTagName('format')[0]
    print ("Format: %s"% format.childNodes[0].data)
   
    rating=movie.getElementsByTagName('rating')[0]
    print("Rating: %s"%rating.childNodes[0].data)

    description=movie.getElementsByTagName('description')[0]
    print("Description: %s"%description.childNodes[0].data)


'Python > Python 3.x' 카테고리의 다른 글

mmapFork.py  (0) 2015.03.06
mmapTest.py  (0) 2015.03.06
xmlSax.py  (0) 2015.03.06
threadingLock.py  (0) 2015.03.06
threadingEx.py  (0) 2015.03.05
Posted by af334