Récupération des enfants d'un noeud
Bonjour
Voici mon problème : je veux écrire une fonction qui doit analyser le fichier XML suivant dont je vous passe un extrait :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
<interaction>
<names>
<shortLabel>virf-ask1</shortLabel>
<fullName>Yeast 2 hybrid analysis reveals interaction between the VirF protein of Agrobacterium tunifaciens and the ASK1 protein</fullName>
</names>
<experimentList>
<experimentRef ref="EBI-605982"/>
</experimentList>
<participantList>
<proteinParticipant>
<proteinInteractorRef ref="EBI-605118"/>
<role>bait</role>
</proteinParticipant>
<proteinParticipant>
<proteinInteractorRef ref="EBI-532357"/>
<role>prey</role>
</proteinParticipant>
</participantList>
<interactionType>
<names>
<shortLabel>physical interaction</shortLabel>
<fullName>physical interaction</fullName>
</names>
<xref>
<primaryRef db="psi-mi" id="MI:0218"/>
<secondaryRef db="pubmed" id="14755292"/>
</xref>
</interactionType>
<confidence unit="UI" value="8"/>
<xref>
<primaryRef db="intact" id="EBI-606054" secondary="virf-ask1"/>
</xref>
<attributeList>
<attribute name="kd">1.0</attribute>
</attributeList>
</interaction> |
Voici ma fonction :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
private void makeInteraction(Element current, int depth) {
Protein P;
int confidence = 0;
String identity = "";
Interaction interaction = new Interaction();
List children = current.getChildren();
Iterator i = children.iterator();
while (i.hasNext()) {
org.jdom.Element e = (Element) i.next();
String child = e.getName();
if (child.compareTo("interaction") == 0) {
System.out.println("interaction trouvé");
List list = e.getChildren("proteinInteractorRef");
Iterator it = list.iterator();
while (it.hasNext()) {
System.out.println("pir trouvé");
org.jdom.Element elm = (Element) it.next();
tour++;
if (tour % 2 != 0) {
identity = elm.getAttributeValue("ref");
System.out.println("id = "+identity);
if (!depart.contains(identity))
depart.add(identity);
for (int k = 0; k < proteinList.size(); k++) {
P = (Protein) proteinList.get(k);
if (P.id.compareTo(identity) == 0) {
place = k;
}
}
} else {
identity = e.getAttributeValue("ref");
}
org.jdom.Element el = e.getChild("confidence");
if (el != null) {
try {
System.out.println("confidence trouvé");
confidence = Integer.parseInt(el
.getAttributeValue("value"));
} catch (NumberFormatException nfe) {
}
}
interaction.confidence = confidence;
interaction.id = identity;
P = (Protein)proteinList.get(place);
P.interactorList.add(interaction);
}
}
makeInteraction(e, depth+1);
}
} |
Mon souci est qu'elle trouve effectivement le noeud interaction. Mais je veux ensuite pourvoir lister et récupérer des infos de certains enfants de ce noeud. Par exemple, je veux récupérer tous les noeuds proteinInteractorRef. Si j'ai bien compris, je peux utiliser sur le noeud en cours getChildren("proteinInteractorRef"). Seulement, au final, je ne retire rien. pareil pourla détection du noeud confidence.
Où ai-je fait mon erreur ?
Merci d'avance de vos réponses.
@++