import xml.dom.minidomdocument = """\<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)def getText(nodelist):rc = []for node in nodelist:if node.nodeType == node.TEXT_NODE:rc.append(node.data)return ''.join(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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。