Send XML to a Perl script

Posted on 2008-11-06
Last Modified: 2013-11-10
I am trying to write a RESTful web service in Perl.

I have a perl script that can read in XML using XML::Simple which is sitting at a particular URL. I want to send XML to that script from another thing (be it a web page, application etc.).

What I don't know is how I'd go about getting the Perl to realise XML was being sent to it and load that XML into XML::Simple (or any other XML module if another is more relevant).

Thanks for any help
Question by:intechfs
    LVL 84

    Expert Comment

    are you trying to do this by modifying the code in the script, or by invoking the script in a particular way?
    in either case it may help to see how the script is now realizing its input.

    Author Comment

    The XML is sent from something, like say a PHP script which calls the Perl at a particular URL.

    I don't want to have to attach it as a GET variable or POST if it can be avoided.

    I haven't written the Perl that reads in the XML yet, but when I do I will probably be using XML::Simple to do so.
    LVL 39

    Accepted Solution

    If the script is being called as a URL, it is likely getting it's data the same way a GET or POST request would.  If so, you can use the CGI module to handle getting the data.  Something like this:
    ########## To display all parameters
    use strict;
    use CGI ':standard';
    print header('text/plain');
    foreach (param()) {
        print "$_ = " . join(", ", param($_)) . "\n";
    ########## To get one, and use it with XML::Simple
    use strict;
    use CGI ':standard';
    use XML::Simple;
    my $XMLstring = param('XML');
    my $xml = XMLin($XMLstring);
    #Now, $xml is a reference to your xml data

    Open in new window


    Author Closing Comment

    Thanks for this, works great.
    LVL 2

    Expert Comment

    I wanna know how can i send an XML to a perl web service from a php page? So many of the articles in the web shows that a request must be a HTTP GET/POST only. If it so then how can i send an XML as a input to a perl web service?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    Forum or Message Board with SMS notifications 5 86
    How do i set default values to a map 4 23
    HTTP POST URL 2 67
    Perl string filter 5 45
    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video is a brief demonstration on how to use security groups and Network Access Control Lists (ACLs) in Amazon Web Services.  Security groups and Network ACLs are mechanisms you can use in AWS to control network traffic.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now