How do i read the all the text within in the <context>...</context>
tag? And how about the <head>...<\head>
tag within the <context \>
tag?
I've an XML file that looks like this:
<corpus lang="english">
<lexelt item="coach.n">
<instance id="1">
<context>I'll buy a train or <head>coach</head> ticket.</context>
</instance>
<instance id="2">
<context>A branch line train took us to Aubagne where a <head>coach</head> picked us up for the journey up to the camp.</context>
</instance>
</lexelt>
</corpus>
But when i ran my code to read the XML text within the ..., I'm only getting the text until i reach the tag.
import xml.etree.ElementTree as et
inputfile = "./coach.data"
root = et.parse(open(inputfile)).getroot()
instances = []
for corpus in root:
for lexelt in corpus:
for instance in lexelt:
instances.append(instance.text)
j=1
for i in instances:
print "instance " + j
print "left: " + i
print "\n"
j+=1
Now I'm just getting the left side:
instance 1
left: I'll buy a train or
instance 2
left: A branch line train took us to Aubagne where a
The output needs also the right side of the context and the head, it should be:
instance 1
left: I'll buy a train or
head: coach
right: ticket.
instance 2
left: A branch line train took us to Aubagne where a
head: coach
right: picked us up for the journey up to the camp.