Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b866770

Browse files
committed
Move the long minidom example to a separate file; \verbatiminput does the
right thing with page breaks in long examples, while the verbatim environment does not. This causes the example to wrap to the next page instead of overwriting the page footer and bottom margin.
1 parent cb6d0da commit b866770

2 files changed

Lines changed: 66 additions & 67 deletions

File tree

Doc/lib/minidom-example.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import xml.dom.minidom
2+
3+
document = """\
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+
19+
dom = xml.dom.minidom.parseString(document)
20+
21+
space = " "
22+
def 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+
29+
def 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+
37+
def handleSlides(slides):
38+
for slide in slides:
39+
handleSlide(slide)
40+
41+
def handleSlide(slide):
42+
handleSlideTitle(slide.getElementsByTagName("title")[0])
43+
handlePoints(slide.getElementsByTagName("point"))
44+
45+
def handleSlideshowTitle(title):
46+
print "<title>%s</title>" % getText(title.childNodes)
47+
48+
def handleSlideTitle(title):
49+
print "<h2>%s</h2>" % getText(title.childNodes)
50+
51+
def handlePoints(points):
52+
print "<ul>"
53+
for point in points:
54+
handlePoint(point)
55+
print "</ul>"
56+
57+
def handlePoint(point):
58+
print "<li>%s</li>" % getText(point.childNodes)
59+
60+
def handleToc(slides):
61+
for slide in slides:
62+
title = slide.getElementsByTagName("title")[0]
63+
print "<p>%s</p>" % getText(title.childNodes)
64+
65+
handleSlideshow(dom)

Doc/lib/xmldomminidom.tex

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -143,73 +143,7 @@ \subsection{DOM Example \label{dom-example}}
143143
program. In this particular case, we do not take much advantage
144144
of the flexibility of the DOM.
145145

146-
\begin{verbatim}
147-
import xml.dom.minidom
148-
149-
document = """\
150-
<slideshow>
151-
<title>Demo slideshow</title>
152-
<slide><title>Slide title</title>
153-
<point>This is a demo</point>
154-
<point>Of a program for processing slides</point>
155-
</slide>
156-
157-
<slide><title>Another demo slide</title>
158-
<point>It is important</point>
159-
<point>To have more than</point>
160-
<point>one slide</point>
161-
</slide>
162-
</slideshow>
163-
"""
164-
165-
dom = xml.dom.minidom.parseString(document)
166-
167-
space = " "
168-
def getText(nodelist):
169-
rc = ""
170-
for node in nodelist:
171-
if node.nodeType == node.TEXT_NODE:
172-
rc = rc + node.data
173-
return rc
174-
175-
def handleSlideshow(slideshow):
176-
print "<html>"
177-
handleSlideshowTitle(slideshow.getElementsByTagName("title")[0])
178-
slides = slideshow.getElementsByTagName("slide")
179-
handleToc(slides)
180-
handleSlides(slides)
181-
print "</html>"
182-
183-
def handleSlides(slides):
184-
for slide in slides:
185-
handleSlide(slide)
186-
187-
def handleSlide(slide):
188-
handleSlideTitle(slide.getElementsByTagName("title")[0])
189-
handlePoints(slide.getElementsByTagName("point"))
190-
191-
def handleSlideshowTitle(title):
192-
print "<title>%s</title>" % getText(title.childNodes)
193-
194-
def handleSlideTitle(title):
195-
print "<h2>%s</h2>" % getText(title.childNodes)
196-
197-
def handlePoints(points):
198-
print "<ul>"
199-
for point in points:
200-
handlePoint(point)
201-
print "</ul>"
202-
203-
def handlePoint(point):
204-
print "<li>%s</li>" % getText(point.childNodes)
205-
206-
def handleToc(slides):
207-
for slide in slides:
208-
title = slide.getElementsByTagName("title")[0]
209-
print "<p>%s</p>" % getText(title.childNodes)
210-
211-
handleSlideshow(dom)
212-
\end{verbatim}
146+
\verbatiminput{minidom-example.py}
213147

214148

215149
\subsection{minidom and the DOM standard \label{minidom-and-dom}}

0 commit comments

Comments
 (0)