title: Iterate through a XML file using Depth-first seach method using XPATH (or anything else) in Python
body: <p>I am trying to iterate thought all the menu of an application automatically. This is a part of the XML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ke3600-menu-file language="en" display="English" index="1"&gt;
    &lt;version major="0" minor="1" patch="0"/&gt;
    &lt;locale name="en_EN" timezone="CET-1CEST,M3.5.0,M10.5.0/3"/&gt;
    &lt;menu name="main_menu" display="Main Menu"&gt;
      &lt;menu name="broadband" display="Broadband" help="100_help_broadband"&gt;
        &lt;onenter proc="activateGfast"/&gt;
        &lt;menu name="load_save_profiles" display="Load and Save Profiles" help="601_help_profiles"&gt;
          &lt;application name="load_profiles" display="Load Profile"/&gt;
          &lt;application name="save_profiles" display="Save Profile"/&gt;
          &lt;application name="remove_profiles" display="Delete Profile"/&gt;
        &lt;/menu&gt;
        &lt;parameter type="list" name="wanInterface" display="Interface" help="101_help_wanInterface"&gt;
          &lt;value id="0" name="ifDSL" display="xDSL"/&gt;
          &lt;value id="1" name="ifSFP" display="SFP"/&gt;
          &lt;value id="2" name="ifETH" display="Ethernet"/&gt;
          &lt;!-- &lt;value i d="3" name="ifWLAN" display="WLAN"/&gt; --&gt;
          &lt;value id="4" name="ifSHDSL" display="SHDSL"/&gt;
        &lt;/parameter&gt;
  
        &lt;menu name="xdslinterface" display="xDSL Interface" help="200_help_xDslInterface"&gt;
          &lt;parameter type="list" name="annex" display="xDSL Mode" help="201_help_xdslModi"&gt;
            &lt;value id="0" name="xdsl_line_annex_a" display="Annex A/M"/&gt;
            &lt;value id="1" name="xdsl_line_annex_b" display="Annex B/J"/&gt;
          &lt;/parameter&gt;
          &lt;application name="xdsl_macAddr" display="MAC Address" caption="MAC Address"&gt;
            &lt;param type="string" name="xdsl_mac_addr" display="MAC Address" length="25"/&gt;
          &lt;/application&gt;
          &lt;parameter type="list" name="xdsl_vectoring_mode" display="Vectoring Mode" help="202_help_Vectoring"&gt;
            &lt;value id="0" name="xdsl_vectoring_mode_disabled" display="Disabled"/&gt;
            &lt;value id="1" name="xdsl_vectoring_mode_enabled" display="Enabled"/&gt;
            &lt;value id="2" name="xdsl_vectoring_mode_friendly" display="Friendly"/&gt;
          &lt;/parameter&gt;
          &lt;parameter type="list" name="xdsl_gfast_mode" display="G.FAST"&gt;
            &lt;value id="0" name="xdsl_gfast_mode_disabled" display="Disabled"/&gt;
            &lt;value id="1" name="xdsl_gfast_mode_enabled" display="Enabled"/&gt;
          &lt;/parameter&gt;
          &lt;parameter type="list" name="resync" display="Auto Re-Sync"&gt;
            &lt;value id="1" name="re_sync_on" display="On"/&gt;
            &lt;value id="0" name="re_sync_off" display="Off"/&gt;
          &lt;/parameter&gt;
          &lt;parameter type="list" name="seamlessRateAdaption" display="Seamless Rate Adaption"&gt;
            &lt;value id="0" name="sra_off" display="Off"/&gt;
            &lt;value id="1" name="sra_on" display="On"/&gt;
          &lt;/parameter&gt;
          &lt;parameter type="list" name="xdsl_ginp" display="G.INP"&gt;
            &lt;value id="0" name="xdsl_ginp_none" display="Off"/&gt;
            &lt;value id="1" name="xdsl_ginp_down" display="Down"/&gt;
            &lt;value id="2" name="xdsl_ginp_up" display="Up"/&gt;
            &lt;value id="3" name="xdsl_ginp_both" display="Down/Up"/&gt;
          &lt;/parameter&gt;
          &lt;parameter type="list" name="power_cut_back" display="Power Cut Back"&gt;
            &lt;value id="0" name="power_cut_back_off" display="Off"/&gt;
            &lt;value id="1" name="power_cut_back_on" display="On"/&gt;
          &lt;/parameter&gt;
          &lt;parameter type="list" name="atmType" display="ATM Type"&gt;
            &lt;value id="0" name="atm_type_aal5" display="AAL5"/&gt;
            &lt;value id="1" name="atm_type_aal0pkt" display="AAL0PKT"/&gt;
            &lt;value id="2" name="atm_type_aal0cell" display="AAL0CELL"/&gt;
          &lt;/parameter&gt;
          &lt;parameter type="list" name="voip_atmType" display="Voip Interface ATM Type"&gt;
            &lt;value id="0" name="voip_atm_type_aal5" display="AAL5"/&gt;
            &lt;value id="1" name="voip_atm_type_aal0pkt" display="AAL0PKT"/&gt;
            &lt;value id="2" name="voip_atm_type_aal0cell" display="AAL0CELL"/&gt;
          &lt;/parameter&gt;
          &lt;parameter type="list" name="iptv_atmType" display="Iptv Interface ATM Type"&gt;
            &lt;value id="0" name="iptv_atm_type_aal5" display="AAL5"/&gt;
            &lt;value id="1" name="iptv_atm_type_aal0pkt" display="AAL0PKT"/&gt;
            &lt;value id="2" name="iptv_atm_type_aal0cell" display="AAL0CELL"/&gt;
          &lt;/parameter&gt;
        &lt;/menu&gt;
  
        &lt;menu name="ethernetinterface" display="Ethernet Interface" help="300_help_ethernetInterface"&gt;
          &lt;parameter type="list" name="ethInterfaceAuto" display="Autonegotiation"&gt;
            &lt;value id="1" name="ethInterfaceAutoOn" display="On"/&gt;
            &lt;value id="0" name="ethInterfaceAutoOff" display="Off"/&gt;
          &lt;/parameter&gt;
          &lt;parameter type="list" name="ethInterfaceSpeed" display="Speed"&gt;
            &lt;value id="2" name="ethIf1000" display="1000MBit/s"/&gt;
            &lt;value id="1" name="ethIf100" display="100MBit/s"/&gt;
            &lt;value id="0" name="ethIf10" display="10MBit/s"/&gt;
          &lt;/parameter&gt;
          &lt;parameter type="list" name="ethInterfaceDuplexMode" display="Duplex Mode"&gt;
            &lt;value id="1" name="ethIfFull" display="Full"/&gt;
            &lt;value id="0" name="ethIfHalf" display="Half"/&gt;
          &lt;/parameter&gt;
        &lt;/menu&gt;
  </code></pre>
  
  <p>I want to make a loop that will go through all the menu using a depth first search (traversing tree starting at the root and explore as far as possible along each branch before backtracking) method. So far I can get the value of a specific node, but I can't figure out how can I automatically go through all the <code>menu</code>, <code>submenu</code>, <code>application</code>, <code>parameter</code>, <code>value</code> and print their <code>display</code> value. Here is the code I have to get the <code>display</code> value of a specific branch.</p>
  
  <pre><code>import xml.etree.ElementTree as ET
  
  def main():
      tree = ET.parse("/home/mr/Desktop/git/KE3600_APP/menu.xml")
      result = ''
      root = tree.getroot()
  
      for e in tree.findall('.//'):
          test.log(str(root.attrib.get('display')))
  </code></pre>
  
  <p>I have looked into various tutorials, but all of them just goes to a specific node and extract the value, none of them goes through all of them. Please suggest me any tutorial or any sample solution that will help me solve this issue. </p>