I am parsing a XML file using xml.etree.ElementTree, and I am reading a xml, however when it runs, I can't take the information because the lines rpc-reply and interfaces have the message-id and xmlns. (Here I only paste one part of my xml). So, if I delete manualy the message-id xxx and xmlns xxx I can parse the xml, if not, I can not take the information. Whay should I add to my python code? and take properly the information. The idea is not delete manually the lines that I commented.
<?xml version="1.0"?>
<rpc-reply message-id="urn:uuid:1577eb48-18f7-4818-afde-468fe24382d7" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<data>
<interfaces xmlns="http://openconfig.net/yang/interfaces">
<interface>
<name>Loopback102</name>
<state>
<name>Loopback102</name>
My python code is:
for data in root.findall('data'):
for interfaces in data.findall('interfaces'):
for interfacen in interfaces.findall('interface'):
for state in interfacen.findall('state'):
inter = state.find('name').text
portoperationalstate = state.find('oper-status').text
protocol = state.find('admin-status').text
info1 = state.find('description').text
I solved it this way:
I used info related to namespace from https://docs.python.org/3/library/xml.etree.elementtree.html