blob: 3745ca1a330b3e1b5110047d84fc1691fa175e01 [file] [log] [blame]
Fred Drakeb8667702001-09-02 06:07:36 +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
21space = " "
22def getText(nodelist):
23 rc = ""
24 for node in nodelist:
25 if node.nodeType == node.TEXT_NODE:
26 rc = rc + node.data
27 return rc
28
29def handleSlideshow(slideshow):
30 print "<html>"
31 handleSlideshowTitle(slideshow.getElementsByTagName("title")[0])
32 slides = slideshow.getElementsByTagName("slide")
33 handleToc(slides)
34 handleSlides(slides)
35 print "</html>"
36
37def handleSlides(slides):
38 for slide in slides:
39 handleSlide(slide)
40
41def handleSlide(slide):
42 handleSlideTitle(slide.getElementsByTagName("title")[0])
43 handlePoints(slide.getElementsByTagName("point"))
44
45def handleSlideshowTitle(title):
46 print "<title>%s</title>" % getText(title.childNodes)
47
48def handleSlideTitle(title):
49 print "<h2>%s</h2>" % getText(title.childNodes)
50
51def handlePoints(points):
52 print "<ul>"
53 for point in points:
54 handlePoint(point)
55 print "</ul>"
56
57def handlePoint(point):
58 print "<li>%s</li>" % getText(point.childNodes)
59
60def handleToc(slides):
61 for slide in slides:
62 title = slide.getElementsByTagName("title")[0]
63 print "<p>%s</p>" % getText(title.childNodes)
64
65handleSlideshow(dom)