I am trying to print a specific node from a user uploaded XML file. I have looked into using the SimpleXML extension and cURL to do this to no avail. Here is my current code that POSTS the XML and then prints it into a string with file_get_contents
.
<?php
$file = $_FILES['uploadedFile'];
if (is_uploaded_file($file['tmp_name']) && $file['error'] == 0) {
echo "The file name was: " . $file['name'] . "<br><br>";
echo "The file type is: " . $file['type'] . "<br><br>";
$xml = htmlentities(file_get_contents($file['tmp_name']));
echo "<pre>";
print_r($xml);
echo "</pre>";
echo "Contact Email: ".$xml["data"]["contactEmail"];
}
?>
<!DOCTYPE html>
<head>
<title>Test XML</title>
</head>
<body>
<form action="index.php" method="post" enctype="multipart/form-data">
<input type="file" name="uploadedFile" size="50" maxlength="25"><br>
<input type="submit" name="upload" value="Upload">
</form>
</body>
</html>
This page will be receiving the same structured XML and returns this:
The file name was: Order_100031.xml
The file type is: text/xml
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<data>
<contactEmail>fake@email.com</contactEmail>
<contactTelephone>1234567890</contactTelephone>
<btNameCompany>John Doe</btNameCompany>
<btStreet>123 Testington Blvd</btStreet>
<btAddress2>Apt. 404</btAddress2>
<btCity>Fairchild</btCity>
<btState>WI</btState>
<btZip>54720</btZip>
<btCountry>US</btCountry>
<item>
<quantity>1</quantity>
<productId>201</productId>memo
</item>
</data>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Contact Email: &
I believe that my syntax is wrong when trying to echo
the contactEmail node. Do I need to include the envelope and body when trying to access it?