(python 2.7)I have an XML file with a ip node. I am trying to search the file for a data set that has a port value of 24 and then return the ip address of that data set. I am able to get the cookie number or tableid but not the ip or the ethertype. When I run my code for ip I get the following error: AttributeError: 'NoneType' object has no attribute 'text'
The XML and code is below.
<testdata>
<data>
<tableid>60</tableid>
<port>24</port>
<ethertype>0x800</ethertype>
<ip>123.456.789.103</ip>
<cookie>6</cookie>
</data>
<data>
<tableid>60</tableid>
<port>25</port>
<ethertype>0x800</ethertype>
<ip>123.456.789.103</ip>
<cookie>6</cookie>
</data>
</testdata>
getChildTextbyOtherChild (datafile, pnode, cnode, cvalue, rnode):
tree = ElementTree.parse(datafile)
root = tree.getroot()
for node in root.findall(pnode):
value = node.find(cnode).text
if value == cvalue:
cnodev= node.find(rnode).text
return cnodev
No comments:
Post a Comment