[Tutor] help me please
祝顺民
zhusm@neusoft.com
Wed, 12 Sep 2001 15:16:43 +0800
这是 MIME 格式的具有很多部分消息。
--Boundary_(ID_0oq7fIwnhAjEDPKstES2YQ)
Content-type: text/plain; charset=gb2312
Content-transfer-encoding: QUOTED-PRINTABLE
help me please ,why can't parse the xml on linux.
my os is slcakware -linux-7.0
but the below programme have been executed on the windows 2000.
the programme is cut from the python doc on the www.python.org.
if you can help me .thank u very much.
>>> import xml.dom.minidom
>>>=20
>>> document =3D """\
=2E.. <slideshow>
=2E.. <title>Demo slideshow</title>
=2E.. <slide><title>Slide title</title>
=2E.. <point>This is a demo</point>
=2E.. <point>Of a program for processing slides</point>
=2E.. </slide>
=2E..=20
=2E.. <slide><title>Another demo slide</title>
=2E.. <point>It is important</point>
=2E.. <point>To have more than</point>
=2E.. <point>one slide</point>
=2E.. </slide>
=2E.. </slideshow>
=2E.. """
>>>=20
>>> dom =3D xml.dom.minidom.parseString(document)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.0/xml/dom/minidom.py", line 475, in parseStr=
ing
return _doparse(pulldom.parseString, args, kwargs)
File "/usr/lib/python2.0/xml/dom/minidom.py", line 464, in _doparse
events =3D apply(func, args, kwargs)
File "/usr/lib/python2.0/xml/dom/pulldom.py", line 237, in parseStr=
ing
parser =3D xml.sax.make_parser()
File "/usr/lib/python2.0/xml/sax/__init__.py", line 76, in make_par=
ser
return _create_parser(parser_name)
File "/usr/lib/python2.0/xml/sax/__init__.py", line 101, in _create=
_parser
return drv_module.create_parser()
AttributeError: create_parser
>>>=20
>>> space =3D " "
>>> def getText(nodelist):
=2E.. rc =3D ""
=2E.. for node in nodelist:
=2E.. if node.nodeType =3D=3D node.TEXT_NODE:
=2E.. rc =3D rc + node.data
=2E.. return rc
=2E..=20
>>> def handleSlideshow(slideshow):
=2E.. print "<html>"
=2E.. handleSlideshowTitle(slideshow.getElementsByTagName("title"=
)[0])
=2E.. slides =3D slideshow.getElementsByTagName("slide")
=2E.. handleToc(slides)
=2E.. handleSlides(slides)
=2E.. print "</html>"
=2E..=20
>>> def handleSlides(slides):
=2E.. for slide in slides:
=2E.. handleSlide(slide)
=2E..=20
>>> def handleSlide(slide):
=2E.. handleSlideTitle(slide.getElementsByTagName("title")[0])
=2E.. handlePoints(slide.getElementsByTagName("point"))
=2E..=20
>>> def handleSlideshowTitle(title):
=2E.. print "<title>%s</title>" % getText(title.childNodes)
=2E..=20
>>> def handleSlideTitle(title):
=2E.. print "<h2>%s</h2>" % getText(title.childNodes)
=2E..=20
>>> def handlePoints(points):
=2E.. print "<ul>"
=2E.. for point in points:
=2E.. handlePoint(point)
=2E.. print "</ul>"
=2E..=20
>>> def handlePoint(point):
=2E.. print "<li>%s</li>" % getText(point.childNodes)
=2E..=20
>>> def handleToc(slides):
=2E.. for slide in slides:
=2E.. title =3D slide.getElementsByTagName("title")[0]
=2E.. print "<p>%s</p>" % getText(title.childNodes)
=2E..=20
>>> handleSlideshow(dom)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: There is no variable named 'dom'
--Boundary_(ID_0oq7fIwnhAjEDPKstES2YQ)
Content-type: text/html; charset=gb2312
Content-transfer-encoding: QUOTED-PRINTABLE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dgb231=
2">
<META content=3D"MSHTML 6.00.2462.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#c0c0c0>
<DIV><BR> </DIV>
<DIV><FONT size=3D2>
<DIV><FONT size=3D2>help me please ,why can't parse the xml on linux.=
</FONT></DIV>
<DIV><FONT size=3D2>my os is slcakware -linux-7.0</FONT></DIV>
<DIV><FONT size=3D2>but the below programme have been executed on the=
windows=20
2000.</FONT></DIV>
<DIV>the programme is cut from the python doc on the <A=20
href=3D"http://www.python.org">www.python.org</A>.</DIV>
<DIV>if you can help me .thank u very much.</DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>>>> import xml.dom.minidom<BR>>>&g=
t;=20
<BR>>>> document =3D """\<BR>... <slideshow><BR>...=
=20
<title>Demo slideshow</title><BR>... <slide><tit=
le>Slide=20
title</title><BR>... <point>This is a demo</point><=
BR>...=20
<point>Of a program for processing slides</point><BR>...=
=20
</slide><BR>... <BR>... <slide><title>Another demo=
=20
slide</title><BR>... <point>It is important</point>=
<BR>...=20
<point>To have more than</point><BR>... <point>one=
=20
slide</point><BR>... </slide><BR>... </slideshow><B=
R>...=20
"""<BR>>>> <BR>>>> dom =3D=20
xml.dom.minidom.parseString(document)<BR>Traceback (most recent call=
=20
last):<BR> File "<stdin>", line 1, in ?<BR> File=
=20
"/usr/lib/python2.0/xml/dom/minidom.py", line 475, in=20
parseString<BR> return _doparse(pulldom.parseString=
, args,=20
kwargs)<BR> File "/usr/lib/python2.0/xml/dom/minidom.py", line =
464, in=20
_doparse<BR> events =3D apply(func, args, kwargs)<B=
R> File=20
"/usr/lib/python2.0/xml/dom/pulldom.py", line 237, in=20
parseString<BR> parser =3D xml.sax.make_parser()<BR=
> File=20
"/usr/lib/python2.0/xml/sax/__init__.py", line 76, in=20
make_parser<BR> return _create_parser(parser_name)<=
BR> =20
File "/usr/lib/python2.0/xml/sax/__init__.py", line 101, in=20
_create_parser<BR> return=20
drv_module.create_parser()<BR>AttributeError: create_parser<BR>>&g=
t;>=20
<BR>>>> space =3D " "<BR>>>> def=20
getText(nodelist):<BR>... rc =3D=20
""<BR>... for node in=20
nodelist:<BR>... if=
=20
node.nodeType =3D=3D=20
node.TEXT_NODE:<BR>...  =
; =20
rc =3D rc + node.data<BR>... return rc<BR>...=
=20
<BR>>>> def handleSlideshow(slideshow):<BR>... &n=
bsp; =20
print "<html>"<BR>... =20
handleSlideshowTitle(slideshow.getElementsByTagName("title")[0])<BR>.=
.. =20
slides =3D slideshow.getElementsByTagName("slide")<BR>... =
=20
handleToc(slides)<BR>... =20
handleSlides(slides)<BR>... print "</html&=
gt;"<BR>...=20
<BR>>>> def handleSlides(slides):<BR>... &n=
bsp; for=20
slide in slides:<BR>... =
=20
handleSlide(slide)<BR>... <BR>>>> def=20
handleSlide(slide):<BR>... =20
handleSlideTitle(slide.getElementsByTagName("title")[0])<BR>... =
=20
handlePoints(slide.getElementsByTagName("point"))<BR>... <BR>>>=
> def=20
handleSlideshowTitle(title):<BR>... print=
=20
"<title>%s</title>" % getText(title.childNodes)<BR>...=
=20
<BR>>>> def handleSlideTitle(title):<BR>...  =
; =20
print "<h2>%s</h2>" % getText(title.childNodes)<BR>...=
=20
<BR>>>> def handlePoints(points):<BR>... &n=
bsp; print=20
"<ul>"<BR>... for point in=20
points:<BR>... =20
handlePoint(point)<BR>... print "</ul>"=
<BR>...=20
<BR>>>> def handlePoint(point):<BR>... &nbs=
p; print=20
"<li>%s</li>" % getText(point.childNodes)<BR>... <BR>>=
>>=20
def handleToc(slides):<BR>... for slide in=
=20
slides:<BR>... title =
=3D=20
slide.getElementsByTagName("title")[0]<BR>... =
=20
print "<p>%s</p>" % getText(title.childNodes)<BR>...=20
<BR>>>> handleSlideshow(dom)<BR>Traceback (most recent call=
=20
last):<BR> File "<stdin>", line 1, in ?<BR>NameError: The=
re is no=20
variable named 'dom'</FONT></DIV></FONT></DIV></BODY></HTML>
--Boundary_(ID_0oq7fIwnhAjEDPKstES2YQ)--