From b86677079d95a8296dbc0b5a21311cb68a3c7f40 Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Sun, 2 Sep 2001 06:07:36 +0000 Subject: [PATCH] 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. --- Doc/lib/minidom-example.py | 65 ++++++++++++++++++++++++++++++++++++ Doc/lib/xmldomminidom.tex | 68 +------------------------------------- 2 files changed, 66 insertions(+), 67 deletions(-) create mode 100644 Doc/lib/minidom-example.py diff --git a/Doc/lib/minidom-example.py b/Doc/lib/minidom-example.py new file mode 100644 index 00000000000..3745ca1a330 --- /dev/null +++ b/Doc/lib/minidom-example.py @@ -0,0 +1,65 @@ +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) + +space = " " +def getText(nodelist): + rc = "" + for node in nodelist: + if node.nodeType == node.TEXT_NODE: + rc = rc + node.data + return 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 "%s" % getText(title.childNodes) + +def handleSlideTitle(title): + print "

%s

" % getText(title.childNodes) + +def handlePoints(points): + print "" + +def handlePoint(point): + print "
  • %s
  • " % getText(point.childNodes) + +def handleToc(slides): + for slide in slides: + title = slide.getElementsByTagName("title")[0] + print "

    %s

    " % getText(title.childNodes) + +handleSlideshow(dom) diff --git a/Doc/lib/xmldomminidom.tex b/Doc/lib/xmldomminidom.tex index 9d4f3b6fff3..884e0c5b0f5 100644 --- a/Doc/lib/xmldomminidom.tex +++ b/Doc/lib/xmldomminidom.tex @@ -143,73 +143,7 @@ This example program is a fairly realistic example of a simple program. In this particular case, we do not take much advantage of the flexibility of the DOM. -\begin{verbatim} -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) - -space = " " -def getText(nodelist): - rc = "" - for node in nodelist: - if node.nodeType == node.TEXT_NODE: - rc = rc + node.data - return 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 "%s" % getText(title.childNodes) - -def handleSlideTitle(title): - print "

    %s

    " % getText(title.childNodes) - -def handlePoints(points): - print "" - -def handlePoint(point): - print "
  • %s
  • " % getText(point.childNodes) - -def handleToc(slides): - for slide in slides: - title = slide.getElementsByTagName("title")[0] - print "

    %s

    " % getText(title.childNodes) - -handleSlideshow(dom) -\end{verbatim} +\verbatiminput{minidom-example.py} \subsection{minidom and the DOM standard \label{minidom-and-dom}}