[Python] How to read xml file using python? [duplicate]

Discussão em 'Python' iniciado por Stack, Maio 29, 2025.

  1. Stack

    Stack Membro Participativo

    I I have a xml file like this

    <?xml version="1.0" encoding="UTF-8"?>
    <Automation_Config>
    <Path>
    <Log>.\SERVER.log</Log>
    <Flag_Path>.\Flag</Flag_Path>
    <files>.\PO</files>
    </Path>

    </Automation_Config>


    I want to read the xml file and get the element of those, and assign to variable.

    I tried this, but I can not get the element of Log.

    import xml.dom.minidom
    def main ():
    Load_XML = xml.dom.minidom.parse('D:/Config.xml')
    print (Load_XML.nodeName)
    print (Load_XML.firstChild.tagName)

    Log = Load_XML.getElementsByTagName ("Log")
    print (Log)

    main()

    Continue reading...

Compartilhe esta Página