-3

I need to iterate the xml for tags and its value.

   <root>
        <information>
            <dept>cs</dept>
            <key><name>aaa</name></key>
            <tool>
                <cols>bb</cols>
                <cols>cc</cols>
                <cols>dd</cols>
            </tool>
        </information>
    </root>

I am new to python i need to read the tags as well as tag value. How to achieve this using python xml.dom . How to achieve this?

Thanks in advance

ArockiaRaj
  • 588
  • 4
  • 17
  • 5
    Possible duplicate of [How do I parse XML in Python?](https://stackoverflow.com/questions/1912434/how-do-i-parse-xml-in-python) – FHTMitchell Jul 23 '18 at 09:53

1 Answers1

0

In xml.dom using python you can use as mentioned below

import xml.dom.minidom
    tools= collection.getElementsByTagName("tool")

    for tool in tools:
         cols = tool.getElementsByTagName('cols')
         for col in cols :
                print("Col: %s" % col.childNodes[0].data)