Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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))
Source by www.alixaprodev.com #
 
PREVIOUS NEXT
Tagged: #text #xml #doc #python
ADD COMMENT
Topic
Name
2+4 =