DOM method to go to the tag with particular attribute value ..with example

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • new one
    New Member
    • Jul 2010
    • 3

    #1

    DOM method to go to the tag with particular attribute value ..with example

    DOM method to go to the tag with particular attribute value ..with example
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Here's a simple example:
    Code:
    from xml.dom.minidom import parseString
    xml_str = """<?xml version="1.0" ?>
    <ROOT>
    <pitch>The data is in between opening and closing tags.</pitch>
    <pitch>More data</pitch>
    </ROOT>"""
    
    xmlDoc = parseString(xml_str)
    
    elemList = xmlDoc.getElementsByTagName('pitch')
    elemList is a list of the elements with the tag "pitch". To get the text from the child element:
    Code:
    for elem in elemList:
        for child in elem.childNodes:
            print child.nodeValue

    Comment

    Working...