FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython/Doc/includes/minidom-example.py at 3.10 · python/cpython · GitHub
python
cpython
Repository navigation
Code
Issues
5k+
(5k+)
Pull requests
2.3k
(2.3k)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpython
/
Doc
/
includes
/
minidom-example.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
64 lines (51 loc) · 1.54 KB
Breadcrumbs
cpython
/
Doc
/
includes
/
minidom-example.py
Copy path
File metadata and controls
64 lines (51 loc) · 1.54 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
)
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
)
Back
|
FazBrowse Home
|
New Git URL