I need to parse an xml from the shell. When I send the command
telnet IP_addr port
so from a python script I do:
subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
where cmd is my command.
I obtain an XML that I have to parse This is my output:
Trying 10.1.6.123...
Connected to 10.1.6.123.
Escape character is '^]'.
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="14">
<g>
<V>13</V>
<E>34</E>
<node>
<name>172.16.102.116</name>
<id>172.16.102.116</id>
<regen_pools>
<count>0</count>
<item_version>0</item_version>
</regen_pools>
<osnr_db>0.000000000e+00</osnr_db>
<osnr>
<count>0</count>
<item_version>0</item_version>
</osnr>
</node>
....
I have already wrote the code to parse that when it is saved into a file, removing the first three lines.
import xml.etree.ElementTree as ET
tree = ET.parse('topo.xml')
root = tree.getroot()
graph={}
app=[]
for vertex in root.findall('g/node'):
key = vertex.find('id').text
But the xml is passed as a file. How to do it whitout create a file?
Thanks a lot Silvia