[Python-checkins] CVS: python/dist/src/Doc/lib minidom-example.py,NONE,1.1 xmldomminidom.tex,1.3,1.4

Fred L. Drake fdrake@users.sourceforge.net
Sat, 01 Sep 2001 23:07:38 -0700


Update of /cvsroot/python/python/dist/src/Doc/lib
In directory usw-pr-cvs1:/tmp/cvs-serv29330

Modified Files:
	xmldomminidom.tex 
Added Files:
	minidom-example.py 
Log Message:
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.


--- NEW FILE: minidom-example.py ---
import xml.dom.minidom

document = """\
<slideshow>
<title>Demo slideshow</title>
<slide><title>Slide title</title>
<point>This is a demo</point>
<point>Of a program for processing slides</point>
</slide>

<slide><title>Another demo slide</title>
<point>It is important</point>
<point>To have more than</point>
<point>one slide</point>
</slide>
</slideshow>
"""

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 "<html>"
    handleSlideshowTitle(slideshow.getElementsByTagName("title")[0])
    slides = slideshow.getElementsByTagName("slide")
    handleToc(slides)
    handleSlides(slides)
    print "</html>"

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 "<title>%s</title>" % getText(title.childNodes)

def handleSlideTitle(title):
    print "<h2>%s</h2>" % getText(title.childNodes)

def handlePoints(points):
    print "<ul>"
    for point in points:
        handlePoint(point)
    print "</ul>"

def handlePoint(point):
    print "<li>%s</li>" % getText(point.childNodes)

def handleToc(slides):
    for slide in slides:
        title = slide.getElementsByTagName("title")[0]
        print "<p>%s</p>" % getText(title.childNodes)

handleSlideshow(dom)

Index: xmldomminidom.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/xmldomminidom.tex,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** xmldomminidom.tex	2001/01/22 19:06:20	1.3
--- xmldomminidom.tex	2001/09/02 06:07:36	1.4
***************
*** 144,214 ****
  of the flexibility of the DOM.
  
! \begin{verbatim}
! import xml.dom.minidom
! 
! document = """\
! <slideshow>
! <title>Demo slideshow</title>
! <slide><title>Slide title</title>
! <point>This is a demo</point>
! <point>Of a program for processing slides</point>
! </slide>
! 
! <slide><title>Another demo slide</title>
! <point>It is important</point>
! <point>To have more than</point>
! <point>one slide</point>
! </slide>
! </slideshow>
! """
! 
! 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 "<html>"
!     handleSlideshowTitle(slideshow.getElementsByTagName("title")[0])
!     slides = slideshow.getElementsByTagName("slide")
!     handleToc(slides)
!     handleSlides(slides)
!     print "</html>"
! 
! 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 "<title>%s</title>" % getText(title.childNodes)
! 
! def handleSlideTitle(title):
!     print "<h2>%s</h2>" % getText(title.childNodes)
! 
! def handlePoints(points):
!     print "<ul>"
!     for point in points:
!         handlePoint(point)
!     print "</ul>"
! 
! def handlePoint(point):
!     print "<li>%s</li>" % getText(point.childNodes)
! 
! def handleToc(slides):
!     for slide in slides:
!         title = slide.getElementsByTagName("title")[0]
!         print "<p>%s</p>" % getText(title.childNodes)
! 
! handleSlideshow(dom)
! \end{verbatim}
  
  
--- 144,148 ----
  of the flexibility of the DOM.
  
! \verbatiminput{minidom-example.py}