[Python] Parsing xml with minidom

Discussão em 'Python' iniciado por Stack, Novembro 28, 2024.

  1. Stack

    Stack Membro Participativo

    Using Python, I am trying to parse an XML file that includes the following structure:

    <channel>
    <index>1</index>
    <values>
    <entry>
    <key>SRV_PARAM_CH_ENABLED</key>
    <value xsi:type="xs:boolean" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">false</value>
    </entry>
    <entry>
    <key>SW_PARAMETER_CH_LABEL</key>
    </entry>
    </values>
    </channel>


    How can I obtain the value of key SRV_PARAM_CH_ENABLED if the key is present?

    I am using xml.dom.minidom and am able to read up to the channel using:

    import xml.dom.minidom

    xml_doc = xml.dom.minidom.parse(path)
    root = xml_doc.documentElement

    chns = xml_doc.getElementsByTagName('channel')

    for chn in chns:
    idxx = chn.getElementsByTagName('index')
    idx = idxx[0].childNodes[0].data # Gets ch number



    but am stumped after that.

    Continue reading...

Compartilhe esta Página