Leser: 1
|< 1 2 >| | 19 Einträge, 2 Seiten |
no element found at line 1, column 0, byte 0 at /usr/local/lib/perl5/site_perl/5.8.8/i686-linux/XML/Parser.pm line 187
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
52
#!/usr/local/bin/perl -w
#use strict;
#use warnings;
use DBI;
use Net::MySQL;
use HTTP::Request::Common;
use LWP::UserAgent;
use CGI qw(header -no_debug);
use XML::Simple;
#==============================database connection================================================
#=============================end database connection==================================================
$mysql->query(qq{SELECT accession_code FROM protein});
my $record_set = $mysql->create_record_iterator;
while (my $record = $record_set->each) {
print "Accession ID: $record->[0] \n";
#For retrieving data from a url post in perl, we will use the LWP module "get" function
use LWP::Simple; #supports the "get" function
$baseurl="http://eutils.ncbi.nlm.nih.gov/entrez/eutils/";
$eutil="esearch.fcgi?";
$parameters="db=protein&term=$record->[0]&retmode=xml";
$url=$baseurl.$eutil.$parameters;
$raw=get($url);
open(FILE, ">$record->[0].xml");
print FILE $raw;
# create object
my $xml = new XML::Simple or die "new failed";
# read XML file
my $data = $xml->XMLin("$record->[0].xml") or die "parse failed";
# access XML data
print "$data->{Id} \n";
close FILE;
unlink("$record->[0].xml");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0"?>
<!DOCTYPE eSearchResult PUBLIC "-//NLM//DTD eSearchResult, 11 May 2002//EN" "http://www.ncbi.nlm.nih.gov/entrez/query/DTD/eSearch_020511.dtd">
<eSearchResult>
<Count>1</Count>
<RetMax>1</RetMax>
<RetStart>0</RetStart>
<IdList>
<Id>29427659</Id>
</IdList>
<TranslationSet>
</TranslationSet>
<TranslationStack>
<TermSet>
<Term>140U_DROME[All Fields]</Term>
<Field>All Fields</Field>
<Count>1</Count>
<Explode>Y</Explode>
</TermSet>
<OP>GROUP</OP>
</TranslationStack>
</eSearchResult>
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/local/bin/perl -w
#use strict;
#use warnings;
use DBI;
use Net::MySQL;
use HTTP::Request::Common;
use LWP::UserAgent;
use CGI qw(header -no_debug);
use XML::Twig;
#==============================database connection================================================
#=============================end database connection==================================================
$mysql->query(qq{SELECT accession_code FROM protein});
my $record_set = $mysql->create_record_iterator;
while (my $record = $record_set->each) {
print "Accession ID: $record->[0] \n";
#For retrieving data from a url post in perl, we will use the LWP module "get" function
use LWP::Simple; #supports the "get" function
$baseurl="http://eutils.ncbi.nlm.nih.gov/entrez/eutils/";
$eutil="esearch.fcgi?";
$parameters="db=protein&term=$record->[0]&retmode=xml";
$url=$baseurl.$eutil.$parameters;
$raw=get($url);
open(FILE, ">$record->[0]");
print FILE $raw;
close FILE;
$xml_file = $record->[0];
my $twig= XML::Twig->new(
TwigHandlers => {
"/eSearchResult/IdList/Id" => \&id_Tag
}
);
#actually parse the file
$twig->parsefile($xml_file) or die "cannot parse [$xml_file]: $!";
###########################################
sub id_Tag {
###########################################
my($t, $idTag)= @_;
print $idTag->text(), "\n";
# Release memory of processed tree up to here
$t->purge();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/perl
use strict;
use warnings;
use XML::Twig;
my $twig= XML::Twig->new(
TwigHandlers => {
"eSearchResult/IdList/Id" => \&id_Tag
}
);
$twig->parsefile("bla.xml") or die "cannot parse : $!";
sub id_Tag {
my($t, $idTag)= @_;
print $idTag->text(), "\n";
# Release memory of processed tree up to here
$t->purge();
}
1
2
3
4
5
6
7
8
9
10
11
12
###########################################
sub id_Tag {
###########################################
my($t, $idTag)= @_;
unless($idTag->text()) {
print "ID-tag leer\n";
}
print $idTag->text(), "\n";
# Release memory of processed tree up to here
$t->purge();
}
|< 1 2 >| | 19 Einträge, 2 Seiten |