import xml.dom.minidom
document = """\
Demo slideshow
Slide title
This is a demo
Of a program for processing slides
Another demo slide
It is important
To have more than
one slide
"""
dom = xml.dom.minidom.parseString(document)
def getText(nodelist):
rc = []
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
return ''.join(rc)
def handleSlideshow(slideshow):
print("")
handleSlideshowTitle(slideshow.getElementsByTagName("title")[0])
slides = slideshow.getElementsByTagName("slide")
handleToc(slides)
handleSlides(slides)
print("")
def handleSlides(slides):
for slide in slides:
handleSlide(slide)
def handleSlide(slide):
handleSlideTitle(slide.getElementsByTagName("title")[0])
handlePoints(slide.getElementsByTagName("point"))
def handleSlideshowTitle(title):
print(f"
{getText(title.childNodes)}")
def handleSlideTitle(title):
print(f"{getText(title.childNodes)}
")
def handlePoints(points):
print("")
for point in points:
handlePoint(point)
print("
")
def handlePoint(point):
print(f"{getText(point.childNodes)}")
def handleToc(slides):
for slide in slides:
title = slide.getElementsByTagName("title")[0]
print(f"{getText(title.childNodes)}
")
handleSlideshow(dom)