Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

i hav written below code to parse xml data.. But I want to send this parsed data to my server side.. Can any one guide me how to do that.. I would be really thank full. thanx in advance.. SCRIPT to parse below file
<?xml version ="1.0"?> <customer-data> <customer> <first_name>Frank</first_name> <last_name>Sanbeans</last_name> <dob>3/10</dob> <email>frank@example.com</email> </customer> <customer> <first_name>Sandy</first_name> <last_name>Sanbeans</last_name> <dob>6/12</dob> <email>sandy@example.com</email> </customer> </customer-data>
#!/usr/bin/perl use strict; use XML::Simple; my $xml = XMLin('parsetest.xml',forcearray => 1); foreach my $customer(@{$xml->{customer}}){ print "Name: $customer->{first_name}->[0]"; print "$customer->{last_name}->[0]\n"; print "Birthday: $customer->{dob}->[0]\n"; print "Email-add: $customer->{email}->[0]\n"; }

Replies are listed 'Best First'.
Re: how to send parsed data to server
by LanX (Saint) on May 19, 2014 at 15:43 UTC
    Thats somehow a paradox question, cause XML is supposed to be a good textual format, so why don't you parse it on the "server" side?

    Anyway if the other side also speaks Perl you could use Data::Dumper to serialize¹ the data (if it's purely textual)

    Otherwise JSON and YAML are widespread options.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

    update
    ¹) here a snippet from the docs:

    use Data::Dumper; #... $boo = [ 1, [], "abcd", \*foo, {1 => 'a', 023 => 'b', 0x45 => 'c'}, \\"p\q\'r", $foo, $fuz]; # ... $bar = eval(Dumper($boo)); print($@) if $@; print Dumper($boo), Dumper($bar);

    use $data=Dumper($boo) on sender side and $bar = eval($data) on receiver side.

Re: how to send parsed data to server
by Anonymous Monk on May 19, 2014 at 15:56 UTC

    It's unclear what you mean by "send this parsed data to my server side", could you explain? There are too many protocols (HTTP? SSH? ...) and data exchange formats (XML is one of them) to choose from that someone else could choose one for you without knowing more about what you want to accomplish and what environment / requirements / specifications you are working with.

Re: how to send parsed data to server
by locked_user sundialsvc4 (Abbot) on May 19, 2014 at 18:07 UTC

    There are several ways to do that, then.   What you need to know is what data format the receiving server will expect, and accept.   If you control both sides, then of course the choice is yours.   Otherwise, and given such a slight amount of data as this, you might simply want to send it as GET-style parameters, right on a URL string.   (Look at the URL that is visible at the top of your browser screen right now ... PerlMonks uses this in its URLs to specify what node you’re looking at right now.   Another way to do it is to POST form-data, or maybe an XML or JSON string.   There’s plenty of information already out there, not strictly related to Perl.

Re: how to send parsed data to server
by Anonymous Monk on May 19, 2014 at 16:02 UTC

    I dont want to send my whole xml file. I just want to send the value that is present inside the xml tags. eg: frank,sanbeans. Only the values.

Re: how to send parsed data to server
by Anonymous Monk on May 19, 2014 at 19:20 UTC

    Can any one provide me a simple example to post above data...just few hints

      http://www.somewhere.com/foobar?first_name=Frank&last_name=Sabeans