I'm using Python 3 to parse xml document. When I print the data held between the "Host" tags. I get <Element 'Host' at 0x7f2a037fca48>`. How do I get the string data held by the Element?
When I view the document in Google I can drill into the properties of the "Host" element and see:
tagName: "Host" textContent: "10.10.1.115"
How do get to the "textContent:"?
My code:
import xml.etree.ElementTree as ET
mytree = ET.parse('IPHost-1.xml')
myroot = mytree.getroot()
for x in myroot.findall('IPHostList'):
Name = x.find('Name').text
Host = x.find('Host').text
#HostType = x.find('HostType').text
#IPAddress = x.find('IPAddress.')
#print(Name,IPFamily,HostType,IPAddress)
Result 5.5.5.5 IPv4 IP <Element 'Host' at 0x7f2a037fca48>
My XML Code:
<Name>X-RDP-SERVERS</Name> <Description/> <HostList> <Host>INSE-AA01VRDP014</Host> <Host>INSE-AA01VRDP033</Host> <Host>INSE-AA01VRDP046</Host> </HostList> <IPFamily>IPv4</IPFamily> </IPHostGroup> <IPHostGroup> <Name>I-SYSLOG</Name> <Description/> <HostList> <Host>A-SPIPLOG01</Host> <Host>A-SPIPSEC04</Host> <Host>A-NITRO</Host> </HostList> <IPFamily>IPv4</IPFamily> </IPHostGroup> <IPHostGroup> <Name>X-DMZ-LOCAL</Name> <Description/> <HostList> <Host>INSIDE-SPIVDD011</Host> <Host>INSIDE-SPIVDD021</Host> </HostList> <IPFamily>IPv4</IPFamily> </IPHostGroup> <IPHostGroup> <Name>I-WIFI</Name> <Description/> <HostList> <Host>10.23.0.0</Host> </HostList> <IPFamily>IPv4</IPFamily> </IPHostGroup> <IPHostGroup> <Name>X-SERVERS</Name> <Description/> <HostList> <Host>10.33.0.0</Host> <Host>10.43.0.0</Host> <Host>10.1.24.0</Host> <Host>10.55.2.0</Host> </HostList> <IPFamily>IPv4</IPFamily> </IPHostGroup> </IPGroupList>