blob: 5ee7682c1927124fba3cfea51a21c02bd3b2e870 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001import xml.dom.minidom
2
3document = """\
4<slideshow>
5<title>Demo slideshow</title>
6<slide><title>Slide title</title>
7<point>This is a demo</point>
8<point>Of a program for processing slides</point>
9</slide>
10
11<slide><title>Another demo slide</title>
12<point>It is important</point>
13<point>To have more than</point>
14<point>one slide</point>
15</slide>
16</slideshow>
17"""
18
19dom = xml.dom.minidom.parseString(document)
20
21def getText(nodelist):
Benjamin Peterson2614cda2010-03-21 22:36:19 +000022 rc = []
Georg Brandl116aa622007-08-15 14:28:22 +000023 for node in nodelist:
24 if node.nodeType == node.TEXT_NODE:
Benjamin Peterson2614cda2010-03-21 22:36:19 +000025 rc.append(node.data)
26 return ''.join(rc)
Georg Brandl116aa622007-08-15 14:28:22 +000027
28def handleSlideshow(slideshow):
Collin Winterb13c4932007-08-30 18:50:25 +000029 print("<html>")
Georg Brandl116aa622007-08-15 14:28:22 +000030 handleSlideshowTitle(slideshow.getElementsByTagName("title")[0])
31 slides = slideshow.getElementsByTagName("slide")
32 handleToc(slides)
33 handleSlides(slides)
Collin Winterb13c4932007-08-30 18:50:25 +000034 print("</html>")
Georg Brandl116aa622007-08-15 14:28:22 +000035
36def handleSlides(slides):
37 for slide in slides:
38 handleSlide(slide)
39
40def handleSlide(slide):
41 handleSlideTitle(slide.getElementsByTagName("title")[0])
42 handlePoints(slide.getElementsByTagName("point"))
43
44def handleSlideshowTitle(title):
Collin Winterb13c4932007-08-30 18:50:25 +000045 print("<title>%s</title>" % getText(title.childNodes))
Georg Brandl116aa622007-08-15 14:28:22 +000046
47def handleSlideTitle(title):
Collin Winterb13c4932007-08-30 18:50:25 +000048 print("<h2>%s</h2>" % getText(title.childNodes))
Georg Brandl116aa622007-08-15 14:28:22 +000049
50def handlePoints(points):
Collin Winterb13c4932007-08-30 18:50:25 +000051 print("<ul>")
Georg Brandl116aa622007-08-15 14:28:22 +000052 for point in points:
53 handlePoint(point)
Collin Winterb13c4932007-08-30 18:50:25 +000054 print("</ul>")
Georg Brandl116aa622007-08-15 14:28:22 +000055
56def handlePoint(point):
Collin Winterb13c4932007-08-30 18:50:25 +000057 print("<li>%s</li>" % getText(point.childNodes))
Georg Brandl116aa622007-08-15 14:28:22 +000058
59def handleToc(slides):
60 for slide in slides:
61 title = slide.getElementsByTagName("title")[0]
Collin Winterb13c4932007-08-30 18:50:25 +000062 print("<p>%s</p>" % getText(title.childNodes))
Georg Brandl116aa622007-08-15 14:28:22 +000063
64handleSlideshow(dom)