Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4042458
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:00:31+00:00 2026-05-20T13:00:31+00:00

I need to create a PHP script that receives XML input via an HTTP

  • 0

I need to create a PHP script that receives XML input via an HTTP POST request, processes it, and then returns an XML response. I have spent quite a while attempting this on my own, and here is what I have so far.

I first quickly threw together an HTML form that allows a user to submit XML data as a string, an XML URI as a string, or an XML URI to my PHP script. This form is for testing only, as I am only tasked with creating this script.

In my PHP script I do some input handling…

// Checks that some XML input has been given
if (!(isset($_POST['xmlinput']))) {
    handleErrors("No XML Input Given");
}

// Creates a new DOM Document
$domdoc = new DomDocument;

// Sets the URL of the XML Schema
$xmlschema = "xmlschema.xsd";

// If XML input is a file, tries to load it
if (file_exists($_POST['xmlinput'])) {
    if (!$domdoc->load($_POST['xmlinput'])) {
        handleErrors("Error in XML File");
    }
}
// If XML input is not a file, tries to load it as a string
else {
    if (!$domdoc->loadXML($_POST['xmlinput'])) {
        handleErrors("Error in XML Document");
    }
}

// Validates the XML against the schema
if (!($domdoc->schemaValidate($xmlschema))) {
    handleErrors("XML Does Not Conform To Schema");
}

I then do some stuff based on what the XML data is, and then I want to generate an XML response. I am fairly certain I can create XML in DOM or SimpleXML, but I simply do not understand how to return it to the original page. Also, is this the best method to handle XML input in PHP? I have seen a ton of posts about php://input or $HTTP_RAW_POST_DATA but these don’t seem to be any better than the method I use. Any information you can give me would be a big help. If I can clarify any more, just let me know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T13:00:31+00:00Added an answer on May 20, 2026 at 1:00 pm

    Very simply, you create your xml document using SimpleXml,

    then just

    echo $xml->asXML();

    If you need to post xml data to a webservice,

    You can use the following code to acheive that.

    function do_post_request($url, $data, $optional_headers = null)
    {
      $params = array('http' => array(
                  'method' => 'POST',
                  'content' => $data
                ));
      if ($optional_headers !== null) {
        $params['http']['header'] = $optional_headers;
      }
      $ctx = stream_context_create($params);
      $fp = @fopen($url, 'rb', false, $ctx);
      if (!$fp) {
        throw new Exception("Problem with $url, $php_errormsg");
      }
      $response = @stream_get_contents($fp);
      if ($response === false) {
        throw new Exception("Problem reading data from $url, $php_errormsg");
      }
      return $response;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a php script that takes lots of URL's via POST
we are building a PHP script that we need at work to create reports
I need to create a PHP script that retrieve and update my inventory from
I need to create an ejabberd user from a PHP script. I also need
i have a php script where i need to create a zip archive with
I have a need to create a library of Object Oriented PHP code that
Need your help with my PHP/MYSQL array. I have a php script that selects
I need to create a WAV file in PHP that consists of four repetitions
I am trying to create a PHP script that will create a calendar event
I am trying to write a PHP script that will create an HTML form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.