I try to get all the "username" element from config.xml using xml.etree.ElementTree. But cannot get the data using below code, it return None to me.
import xml.etree.ElementTree as ET
tree = ET.parse('config.xml')
root = tree.getroot()
users = tree.findall('username')
print(users)
If I use above code to test again some normal xml file, it works. Here is the config.xml file that I have to use, maybe there is format issue within this file, but I cannot figure out.
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply
xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:cf3e02a2-b7bc-475f-a87e-b6571eca99b7"
xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<data>
<app-hosting-cfg-data
xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-app-hosting-cfg">
<apps>
<app>
<application-name>guestshell</application-name>
<application-network-resource>
<management-interface-name>0</management-interface-name>
</application-network-resource>
</app>
</apps>
</app-hosting-cfg-data>
<native
xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<version>17.3</version>
<boot-start-marker/>
<boot-end-marker/>
<enable>
<secret>
<type>9</type>
<secret>$9$GNcSrWbM1PyCqU$9.BCza34ClqbgyABGzRV1v5hjCWhaoN9K.gqxCtcCvE</secret>
</secret>
</enable>
<username>
<name>developer</name>
<privilege>15</privilege>
<secret>
<encryption>9</encryption>
<secret>$9$oNguEA9um9vRx.$MsDk0DOy1rzBjKAcySWdNjoKcA7GetG9YNnKOs8S67A</secret>
</secret>
</username>
<username>
<name>netconf</name>
<privilege>15</privilege>
<secret>
<encryption>9</encryption>
<secret>$9$A7TadNm7VSWsXk$k0eVomchjOb90cjpI5hmLA/n0xlomzUhJ47o5y9WMHc</secret>
</secret>
</username>
<username>
<name>restconf</name>
<privilege>15</privilege>
<secret>
<encryption>9</encryption>
<secret>$14$eGCL$P15Lf8exJZB3qk$XYVi2eHOhT895Rpx1gYEQcwWfeML3AavoI/lxrMMtD.</secret>
</secret>
</username>
<username>
<name>root</name>
<privilege>15</privilege>
<secret>
<encryption>9</encryption>
<secret>$9$IRHgr7MCAEFNLk$ZfOrXoRLFhh6gHIxhLPfOC9KzjIWISv4KqkNAR51kmI</secret>
</secret>
</username>
</native>
</data>
</rpc-reply>
usernameelement ? How does your output should look like? Please update the post with the required output