I'm parsing this XML file: https://www.dropbox.com/s/i6hga7nvmcd6rxx/ct.cps?dl=0
From each <Reaction> tag I want its name attribute and the name attribute of its <Constant> children.
from lxml import etree
NSMAP = {"c": "http://www.copasi.org/static/schema"}
parsed = etree.parse('ct.cps')
for a in parsed.xpath("//c:Reaction", namespaces=NSMAP):
print a.attrib['name']
I can access each of the two elements' name attributes by using the above code. However, when I'm in one iteration of the <Reaction> elements, how could I then access subelements and list them out?
I've tried this:
for a in parsed.xpath("//c:Reaction", namespaces=NSMAP):
for b in a.xpath('Constant'):
print b.attrib['name']
But it doesn't work.
Here's a sample of the XML
</rdf:RDF>
</MiriamAnnotation>
</Metabolite>
</ListOfMetabolites>
<ListOfReactions>
<Reaction key="Reaction_0" name="v1" reversible="false" fast="false">
<MiriamAnnotation>
<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="#Reaction_0">
<dcterms:created>
<rdf:Description>
<dcterms:W3CDTF>2015-06-16T22:13:07Z</dcterms:W3CDTF>
</rdf:Description>
</dcterms:created>
</rdf:Description>
</rdf:RDF>
</MiriamAnnotation>
<ListOfSubstrates>
<Substrate metabolite="Metabolite_5" stoichiometry="1"/>
</ListOfSubstrates>
<ListOfModifiers>
<Modifier metabolite="Metabolite_9" stoichiometry="1"/>
</ListOfModifiers>
<ListOfConstants>
<Constant key="Parameter_4344" name="Kcat" value="433.724"/>
<Constant key="Parameter_4343" name="km" value="479.617"/>
</ListOfConstants>
<KineticLaw function="Function_40">
<ListOfCallParameters>
<CallParameter functionParameter="FunctionParameter_264">
<SourceParameter reference="Parameter_4344"/>
</CallParameter>
<CallParameter functionParameter="FunctionParameter_254">
<SourceParameter reference="Metabolite_9"/>
</CallParameter>
<CallParameter functionParameter="FunctionParameter_258">
<SourceParameter reference="Metabolite_5"/>
</CallParameter>
<CallParameter functionParameter="FunctionParameter_266">
<SourceParameter reference="Parameter_4343"/>
</CallParameter>
</ListOfCallParameters>
</KineticLaw>
</Reaction>
<Reaction key="Reaction_1" name="v2" reversible="false" fast="false">
<MiriamAnnotation>
<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="#Reaction_1">
for b in a.xpath('.//Constant'):?