Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

text from xml doc in python

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>
"""
def getText(nodelist):
    rc = []
    for node in nodelist:
        if node.nodeType == node.TEXT_NODE:
            rc.append(node.data)
    return ''.join(rc)
dom = xml.dom.minidom.parseString(document)
title=dom.getElementsByTagName("title")[0]
slides=dom.getElementsByTagName("slide")
for slide in slides:
    s_title = slide.getElementsByTagName("title")[0]
    print( getText(title.childNodes))
Comment

PREVIOUS NEXT
Code Example
Python :: split path in list of directories 
Python :: stack error: command failed: import sys; print "%s.%s.%s" % sys.version_info[:3]; 
Python :: python get number of arguments of a function 
Python :: xlabel font type matplotlib 
Python :: invert binary tree with python 
Python :: os.startfile() python 
Python :: django create view 
Python :: Creating Python Sets 
Python :: python requests post form data 
Python :: dictionary python values 
Python :: while input is not empty python 
Python :: turtle.write("Sun", move=False, align="left", font=("Arial", 8, "normal")) 
Python :: pandas if python 
Python :: python int string float 
Python :: plotly coordinates mapping 
Python :: size of set python 
Python :: python byte like to string 
Python :: extract a jar py 
Python :: unsplash python 
Python :: how to make a button open a new window in python 
Python :: python obfuscator github 
Python :: remove word from string in python 
Python :: how to install ffmpeg_streaming in python 
Python :: box plot in seaborn 
Python :: labelimg yolo save format 
Python :: numpy random 
Python :: django cleanup 
Python :: boxplot python 
Python :: transform image to rgb python 
Python :: is in array python 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =