Bonjour
J'avoue que le titre est vague, je vais tâcher de vous expliquer. Je dois récupérer certaines infos à partir de fichiers XML. La structure de ce document est telle que :
Ce qui m'intéresse plus particluièrement, c'est de récupérer les attributs protein_name et protein_description.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?xml version="1.0" encoding="UTF-8"?> <protein_summary execution_date="Thu Jul 15 10:55:53 2004" program_version="ProteinProphet.pl v2.0 AKeller August 15, 2003"> <protein_group group_number="1" probability="1.00"> <protein protein_name="UniRef100_Q8IUB0" n_indistinguishable_proteins="10" probability="1.00" percent_coverage="3.2" unique_stripped_peptides="LPLQDVYK" group_sibling_id="a" total_number_peptides="1"> <annotation protein_description="CTCL tumor antigen [Homo sapiens]"/> <indistinguishable_protein protein_name="UniRef100_Q9H2I7"> <annotation protein_description="EF1a-like protein [Homo sapiens]"/> </indistinguishable_protein> <indistinguishable_protein protein_name="UniRef100_Q96RE1"> <annotation protein_description="Translation elongation factor 1 alpha 1-like 14 [Homo sapiens]"/> </indistinguishable_protein> <indistinguishable_protein protein_name="UniRef100_Q8TBL1"> <annotation protein_description="Hypothetical protein [Homo sapiens]"/> </indistinguishable_protein> <indistinguishable_protein protein_name="UniRef100_Q16577"> <annotation protein_description="Oncogene [Homo sapiens]"/> </indistinguishable_protein> <indistinguishable_protein protein_name="UniRef100_Q96CD8"> <annotation protein_description="Hypothetical protein [Homo sapiens]"/> </indistinguishable_protein> <indistinguishable_protein protein_name="UniRef100_Q9NZS6"> <annotation protein_description="Glucocorticoid receptor AF-1 specific elongation factor [Homo sapiens]"/> </indistinguishable_protein> <indistinguishable_protein protein_name="UniRef100_Q96C29"> <annotation protein_description="Hypothetical protein [Homo sapiens]"/> </indistinguishable_protein> <indistinguishable_protein protein_name="UniRef100_Q05639"> <annotation protein_description="Elongation factor 1-alpha 2 [Homo sapiens]"/> </indistinguishable_protein> <indistinguishable_protein protein_name="UniRef100_P04720"> <annotation protein_description="Elongation factor 1-alpha 1 [Homo sapiens]"/> </indistinguishable_protein> <peptide peptide_sequence="LPLQDVYK" charge="2" initial_probability="0.96" nsp_adjusted_probability="1.00" weight="1.00" is_nondegenerate_evidence="Y" n_tryptic_termini="2" n_sibling_peptides="0.00" n_sibling_peptides_bin="0" n_instances="1" is_contributing_evidence="Y"> </peptide> </protein> </protein_group> </protein_summary>
J'ai regardé un peu au niveau des parseurs, mais je dois bien avouer que je débute totalement . Un exemple de code :
Mais bon, ce code ne fonctionne pas. Pouvez-vous m'aider à vaincre XML ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 use XML::Parser; # initialize parser and read the file $parser = new XML::Parser( Style => 'Tree' ); my $tree = $parser->parsefile( "./short.xml" ); # serialize the structure #use Data::Dumper; #print Dumper( $tree ); print "".$tree->{ protein_summary }->{ protein_group }->{ protein=>"protein_name" }."\n";
@ ++
Partager