Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Why XML::Smart module can't work

by sanguine_perl (Initiate)
on Dec 17, 2013 at 09:01 UTC ( #1067438=perlquestion: print w/ replies, xml ) Need Help??
sanguine_perl has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am stuck by the problem of using XML::Smart module, it can't work. Recently, I want to use XML::Smart to parse the XML response, but i can't get any results,so i test the return as follows:
#!/usr/bin/perl use XML::Smart; use Data::Dumper; use warnings; use strict; #open FILE1, 'run.xml' or die $!; my $XML_1 = XML::Smart->new('run.xml'); my $ref = $XML_1->{product}; print $ref;
I expect to see the reference of response, but after running it
C:\Users\rchen4\Desktop\Perl_XML>perl script2.pl C:\Users\rchen4\Desktop\Perl_XML>
no result. XML::Smart and Object::MultiType are all installed. Could someone be helpful?

Comment on Why XML::Smart module can't work
Select or Download Code
Re: Why XML::Smart model can't work
by Random_Walk (Parson) on Dec 17, 2013 at 11:05 UTC

    can you insert print Dumper $XML_1; after my $XML_1 = XML::Smart->new('run.xml'); to check you really got an XML::Smart object.

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!

      Yes, after inserting print Dumper $XML_1, i got the ojbect, but why i can't print $ref?

      My really intention is to parse the result of get request and print the result i wanted into a .csv file.
      #!/usr/bin/perl use XML::Smart; use Data::Dumper; use warnings; use strict; my @array = (); my %data = (); open OUTFILE, '>result2.csv' or die $!; open FILE, 'fund.txt' or die $!; while (<FILE>) { chomp; my $XML = XML::Smart->new("http://cmsbeta.morningstar.com/api/v2 +/2008428323/securities/$_"."/documents?colids=590&fields=*"); print Dumper $XML; eval{ %data = %{$XML->{Document}->{Content}->{People}}; }; for my $li (keys %data){ print "$li:$data{$li}"."\n"; push (@array,$data{$li}); } print OUTFILE ("$_,","@array"."\n"); @array = (); } close(OUTFILE); close(FILE); exit;
      the result i got is
      C:\Users\rchen4\Desktop\Perl_XML>perl parse_prepare.pl Use of uninitialized value $data in pattern match (m//) at C:/Dwimperl +/perl/site /lib/XML/Smart/Tree.pm line 169, <FILE> line 1. $VAR1 = bless( do{\(my $o = bless( { 'tree' => {}, 'a' => [], 'TIEONUSE' => { 'h' => 'XML::Smart::Tie::Has +h', 'a' => 'XML::Smart::Tie::Arr +ay' }, 'parser' => '', 's' => \sub { "DUMMY" }, 'c' => sub { "DUMMY" }, 'point' => ${$VAR1}->{'tree'}, 'h' => {}, 'g' => \*Object::MultiType::Saver::NULL, 'b' => \sub { "DUMMY" } }, 'Object::MultiType::Saver' ))}, 'XML::Smart +' );
      I still got nowhere.I can use XML::Simple to finish the similar task, but i think XML::Smart is more cool so i want to try it.

        That object you got back looks just like mine did when it failed to connect to the URL. Are you sure it is contacting the web server? Try printing "http://cmsbeta.morningstar.com/api/v2/2008428323/securities/$_"."/documents?colids=590&fields=*\n" and check you can connect to the resulting URL, with a browser, from the machine where your Perl is running

        Cheers,
        R.

        Pereant, qui ante nos nostra dixerunt!
Re: Why XML::Smart model can't work (
by Anonymous Monk on Dec 17, 2013 at 11:22 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1067438]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (15)
As of 2014-08-22 15:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (159 votes), past polls