Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

How do I receive an XML file through HTTP?

alohaaaron (Programmer) (OP)
24 Mar 11 15:53
Hi, I have PHP 4.0 so don't have simple XML.  I"m trying to use file_get_contents to read in the XML and then read the file till the end using fopen and other file commands.  Is this correct or does a file actually exist?  Thanks!
 
$xml = file_get_contents ('php://input') or die('file_get_contents (php://input)');

$fp = fopen($xml, 'r');

If I print the contents below using $HTTP_RAW_POST_DATA it displays the XML file that was posted

echo "<pre>";
print_r($HTTP_RAW_POST_DATA );
echo "</pre>";

 
jpadie (TechnicalUser)
24 Mar 11 19:27
you seem to assuming that the xml is available at the standard input.  if you control the source of the xml or the receiving script, why not do the manipulations in that script rather than relying on sockets?
 
alohaaaron (Programmer) (OP)
25 Mar 11 2:48
Thanks.  The file xml file is sent by a 3rd party.  Now I'm trying to put it into a database.  I don't have access to simple xml or open xml.  In the code below it prints out the xml file correctly.  Here is the XML File.
$xml_data = "<?xml version=\"1.0\"?><member><Email>abc@home.com me</Email></member>";

How would I insert the email address into a database?  Even though the email address abc@home.com is printed out correctly as Email: abc@home.com I don't see how to capture that variable and put it into a database?  It's not $element_name since that's the field name.

//Function to use at the start of an element
function start($parser,$element_name,$element_attrs)
{
  switch($element_name)
    {
    case "EMAIL":
    echo "Email: ";    break;
    }
}
jpadie (TechnicalUser)
25 Mar 11 4:32
first of all migrate to php5.  php4 has been end of lifed. people should not be writing new code for a platform that no longer has support.

if you do not have any modern parsing extensions, then consider xml_parse_into_struct.

insert the values into the database in the normal way.
alohaaaron (Programmer) (OP)
25 Mar 11 12:32
Thanks.  I have no control over what my vendor has installed on their platform.  This includes no curl extension and no PHP 5.x

I'll check out the xml_parse_into_struct

 
jpadie (TechnicalUser)
25 Mar 11 17:18
of course you have control.  just vote with your feet.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close