I have a sample XML like below:
<data xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<sessions xmlns="com:infinera:common:session">
<session>
<MoId>admin_12</MoId>
<AccountName>admin</AccountName>
<ProtocolType>SSH</ProtocolType>
<MgmtAppType>CLI</MgmtAppType>
<AuthenticationType>LOCAL</AuthenticationType>
</session>
<session>
<MoId>admin_13</MoId>
<AccountName>admin</AccountName>
<ProtocolType>TELNET</ProtocolType>
<MgmtAppType>TL1</MgmtAppType>
<AuthenticationType>LOCAL</AuthenticationType>
<session>
</sessions>
</data>
Here i want to iterate through the children to find if value of MgmtAppType is TL1 and if it is I want to print all the elements associated it i.e. MoID, AccountName, ProtocolType, MgmtAppType, AuthenticationType. I tried with below code, but this prints only the value of MgmtAppType
import xml.etree.ElementTree as ET
root = ET.parse('C:\\session.xml')
roots = root.getroot()
for sess in roots.iter():
if (sess.tag == "{com:infinera:common:session}MgmtAppType") and (sess.text == "TL1"):
for chd in sess.iter():
print chd.text
How would i print all the elements of particular child node based on the search?