Dear perlMonks,
I have the following problem:
A have an XML output(1GB) of a database of chemical compounds and I would like to extract just some parametrs for every and single of them. I tried to get oriented in examples for XML:twig and the only result of my tries is the code below (XML is completly new for me and perl almost completly). The trouble is that extracting the records of interest(PC-CompoundType_id_cid,PC-InfoData_value_binary) the way I do can lead to troubles when the item for some compound is missing
. Thanks for your help. karpatov
#!/bin/perl -w
use strict;
use XML::Twig;
my $leader_name;
my $leader_score=0;
#my $field0= 'PC-Compound';
my $field1= 'PC-CompoundType_id_cid';
my $field2= 'PC-InfoData_value_binary';
my $twig= new XML::Twig( twig_roots => {$field1 => 1, $field2 => 1
+} );
$twig->parsefile( "D:/NCI-Open/vice shlavickou.xml");
my $root= $twig->root;
my @cpds= $root->children_text($field1);
my @bins= $root->children_text($field2);
print "@cpds\n";
print "@bins\n";
#$twig->print;
Simplified XML:
<PC-Compound>
<PC-Compound_id>
<PC-CompoundType>
<PC-CompoundType_id>
<PC-CompoundType_id_cid>1</PC-CompoundType_id_cid>
</PC-CompoundType_id>
</PC-CompoundType>
</PC-Compound_id>
<PC-Compound_atoms>
</PC-Compound_atoms>
<PC-Compound_props>
<PC-InfoData>
</PC-InfoData>
<PC-InfoData>
<PC-InfoData_urn>
<PC-Urn>
</PC-Urn>
</PC-InfoData_urn>
<PC-InfoData_value>
<PC-InfoData_value_binary>00000371E0723800000000000000000000
+000000000000000000000000000000000000000000001E00000000000814E18006020
+803000400080000900800000000000000000001080000020014008000070000052000
+1000002400000000000000000000000000000000000000000000000000</PC-InfoDa
+ta_value_binary>
</PC-InfoData_value>
</PC-InfoData>
<PC-InfoData>
</PC-InfoData>
</PC-Compound>
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.