I'm currently learning how to work with xml documents. I've got as far as finding out about XML::Simple and working though some examples. Here is my 'test script' as it is at the moment.
#!/usr/bin/perl
# use module
use XML::Simple;
use Data::Dumper;
$xs = new XML::Simple(keeproot => 1,searchpath => ".",
forcearray => 1,);
$ref = $xs->XMLin("test.xml");
print Dumper($ref);
And my data dump looks like this.
$VAR1 = {
'sas_residue_annotation' => [
{
'xmlns' => 'http://www.ebi.a
+c.uk/WSsas/Schema',
'sources' => [
{
'source' => [
{
+ 'source_name' => [
+ '1iho'
+ ],
+ 'ref_evalue' => [
+ '5.5e-50'
+ ],
+ 'ref_overlap' => [
+ '282'
+ ],
+ 'ref_identity' => [
+ '47.20'
+ ],
+ 'ref_pmid' => [
+ '11377204'
+ ]
}
+,
{
+ 'source_name' => [
+ '1mop'
+ ],
+ 'ref_evalue' => [
+ '8.3e-38'
+ ],
+ 'ref_overlap' => [
+ '264'
+ ],
+ 'ref_identity' => [
+ '43.60'
+ ],
+ 'ref_pmid' => [
+ '12717031'
+ ]
}
+,
{
+ 'source_name' => [
+ '1n2b'
+ ],
+ 'ref_evalue' => [
+ '8.2e-38'
+ ],
+ 'ref_overlap' => [
+ '264'
+ ],
+ 'ref_identity' => [
+ '43.60'
+ ],
+ 'ref_pmid' => [
+ '12717031'
+ ]
}
+,
etc ...
I'm not sure how to go about retrieving the information - how I might, for example, just want to print off all the 'source names' in my file. I've tried following a few examples on this today and haven't been able to figure it out yet.
Any tips much appreciated.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.