Solved

Can't load xml file with CDATA - keeps giving errors

Posted on 2013-11-13
25
1,101 Views
Last Modified: 2013-12-01
Hi,
I have a variable ($body) that contains CDATA in all the tags (first example). Other sources when sending a similiar file don't have the CDATA in each of the tags (second example). That seems to be the only difference I can tell. Second example works fine. I'm loading it using this:

$obj = SimpleXML_Load_String($body, 'SimpleXMLElement', LIBXML_NOCDATA);

and stepping through along these lines:
foreach ($obj->prospect->vehicle as $vehicle)
{
    $interest =            (string)$vehicle['interest'];
    $leadType =            (string)strtoupper($vehicle['status']);
    $year =             (string)$vehicle->year;
    $make =             (string)strtoupper($vehicle->make);
    $model =             (string)strtoupper($vehicle->model);
    $vin =                   (string)strtoupper($vehicle->vin);
    $stock =             (string)strtoupper($vehicle->stock);
    $trim =             (string)strtoupper($vehicle->trim);
    $leadVehicle =       (string)strtoupper($year." ".$make." ".$model." ".$trim." ".$stock);
}

These are the errors I'm getting:
PHP Warning:  simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]: Entity: line 5: parser error : StartTag: invalid element name in /home/steeleau/pipes/chatpipe.php on line 53
PHP Warning:  simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]:       &lt;id sequence=&quot;1&quot; source=&quot;Dealer.com&quot;&gt;&lt;!  in /home/steeleau/pipes/chatpipe.php on line 53
... repeats for a ways

<?xml version="1.0"?>
<?ADF version="1.0"?>
<adf>
<prospect status="new">
<id sequence="1" source="Dealer.com"><![CDATA[50aa9ada0a0d0aee137f25427ca04d31]]></id>
<requestdate>2013-11-13T08:53:47-00:00</requestdate>
	<vehicle interest="buy" status="used">
	<year><![CDATA[2011]]></year>
	<make><![CDATA[Chevrolet]]></make>
	<model><![CDATA[Malibu]]></model>
	<vin><![CDATA[1G1ZB5EU9BF127056]]></vin>
	<stock><![CDATA[M1869A]]></stock>
	<trim><![CDATA[LS]]></trim>
	<doors><![CDATA[4 door]]></doors>
	<bodystyle><![CDATA[Sedan]]></bodystyle>
	<transmission><![CDATA[Automatic]]></transmission>
	<odometer status="unknown" units="mi"><![CDATA[91,122]]></odometer>
<colorcombination>
<interiorcolor><![CDATA[Grey]]></interiorcolor>
<exteriorcolor><![CDATA[Blue]]></exteriorcolor>
... and so on...

Open in new window

From other sources the incoming data looks like:
<?xml version="1.0"?> 
<?adf version="1.0"?> 
<adf> 
<prospect>
<requestdate>2013-11-07CST17:50:24-06:00</requestdate>
<vehicle interest="buy" status="used">
<year></year>
<make>Kia</make>
<model>Sorento</model>
<vin></vin>
<stock></stock>
<trim></trim>
</vehicle>
<customer>
<contact>
<name part="first">Earl</name>
<name part="last">X</name>
<email></email>
<phone></phone>
<address>
<street line="1"></street>
<city></city>
<regioncode></regioncode>
<postalcode></postalcode>
<country></country>
</address>
</contact>
...and so on...

Open in new window

Any idea what is going haywire?
0
Comment
Question by:tjyoung
  • 12
  • 7
  • 5
  • +1
25 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Please post a link (or upload a file to EE) that gives us access to the complete data set.  These fragments are not usable and I would like to create a test case so I can see what is really going on.  Thanks, ~Ray
0
 
LVL 1

Author Comment

by:tjyoung
Comment Utility
Hi,
Great, here are 2. One that isn't a problem other that is...
samplecdata.xml
sample-noissue.xml
0
 
LVL 1

Author Comment

by:tjyoung
Comment Utility
I just noticed the CDATA in the trouble file was stripped out (I had used an online formatter to clean it)
Below is the messy but original problem version:

<?xml version="1.0"?>
<?ADF version="1.0"?>
<adf>
       <prospect status="new">
                               <id sequence="1" source="Dealer.com"><![CDATA[50aa9ada0a0d0aee137f25427ca04d31]]></id>
                                                                                                               <requestdate>2013-11-13T08:53:47-00:00</requestdate>
               <vehicle interest="buy" status="used">
                       <year><![CDATA[2011]]></year>
                       <make><![CDATA[Chevrolet]]></make>
                       <model><![CDATA[Malibu]]></model>
                       <vin><![CDATA[1G1ZB5EU9BF127056]]></vin>
                       <stock><![CDATA[M1869A]]></stock>
                       <trim><![CDATA[LS]]></trim>
                       <doors><![CDATA[4 door]]></doors>
                       <bodystyle><![CDATA[Sedan]]></bodystyle>
                       <transmission><![CDATA[Automatic]]></transmission>
                                               <odometer status="unknown" units="mi"><![CDATA[91,122]]></odometer>
                                                                       <colorcombination>
                           <interiorcolor><![CDATA[Grey]]></interiorcolor>
                           <exteriorcolor><![CDATA[Blue]]></exteriorcolor>
                           <preference>1</preference>
                       </colorcombination>
                                               <imagetag><![CDATA[http://images.dealer.com/0247/62beb281acc4a040603853ca74b83d54x.jpg]]></imagetag>
                                               <price type="quote" currency="CAD"><![CDATA[9988]]></price>
                                               <pricecomments><![CDATA[]]></pricecomments>
                                                                       <option>
                           <optionname><![CDATA[AM/FM Stereo]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Air Conditioning]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Alloy Wheels]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Anti-Lock Brakes (ABS)]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Anti-Theft]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Auxiliary 12v Outlet]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Bucket Seats]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[CD Player]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Child-Safety Locks]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Cloth Interior]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Cruise Control]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Driver Side Airbag]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Intermittent Wipers]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Keyless Entry]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Navigation System]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Passenger Airbag]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Power Locks]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Power Mirrors]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                                               <option>
                           <optionname><![CDATA[Power Seat]]></optionname>
                           <weighting></weighting>
                       </option>
                                                                       <comments><![CDATA[]]></comments>
               </vehicle>
               <customer>
                           <contact>
               <name part="first"><![CDATA[Todd]]></name>
               <name part="last"><![CDATA[Testing]]></name>
               <email preferredcontact="1"><![CDATA[tthompson@steeleauto.com]]></email>
               <phone type="voice" time="nopreference"><![CDATA[9024543060]]></phone>
                   <address>
               <street line="1"><![CDATA[]]></street>
               <street line="2"><![CDATA[]]></street>
               <city><![CDATA[]]></city>
       <regioncode><![CDATA[]]></regioncode>
       <postalcode><![CDATA[]]></postalcode>
       <country><![CDATA[]]></country>
   </address>
   </contact>
                       <comments><![CDATA[Just testing integration from AutoTrader now :)]]></comments>
               </customer>
               <vendor>
                                               <vendorname><![CDATA[Steele Cars]]></vendorname>
                                                   <contact>
               <name part="first"><![CDATA[]]></name>
               <name part="last"><![CDATA[]]></name>
               <email><![CDATA[sales@steelecars.com]]></email>
               <phone type="voice" time="nopreference"><![CDATA[902-462-6600]]></phone>
                   <address>
               <street line="1"><![CDATA[15 somewhere Court]]></street>
               <street line="2"><![CDATA[]]></street>
               <city><![CDATA[DARTMOUTH]]></city>
       <regioncode><![CDATA[NS]]></regioncode>
       <postalcode><![CDATA[B2W 0K3]]></postalcode>
       <country><![CDATA[CA]]></country>
   </address>
   </contact>
               </vendor>
                               <provider>
                                                                                               <name part="full"><![CDATA[Dealer.com]]></name>
                                               <service><![CDATA[Test Drive - Dealer.Com Website]]></service>
                       <url><![CDATA[www.dealer.com]]></url>
                       <email><![CDATA[support@dealer.com]]></email>
                       <phone type="voice"><![CDATA[888-895-2994]]></phone>
                           <contact>
               <name part="full"><![CDATA[Dealer.com Support]]></name>
               <email><![CDATA[support@dealer.com]]></email>
               <phone type="voice" time="day"><![CDATA[888-895-2994]]></phone>
                   <address>
               <street line="1"><![CDATA[1 Howard Street]]></street>
               <city><![CDATA[Burlington]]></city>
       <regioncode><![CDATA[VT]]></regioncode>
       <postalcode><![CDATA[05401]]></postalcode>
       <country><![CDATA[US]]></country>
   </address>
   </contact>
               </provider>
                       </prospect>
</adf>

Open in new window

0
 
LVL 42

Expert Comment

by:Chris Stanyon
Comment Utility
The sample you've provided (samplecdata.xml) doesn't have any CDATA in it.

I've tested your code from the original post and it works fine.

What version of PHP are you running?

This works for me:

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

$xmlString = <<<EOT
<?xml version="1.0"?>
<?ADF version="1.0"?>
<adf>
<prospect status="new">
<id sequence="1" source="Dealer.com"><![CDATA[50aa9ada0a0d0aee137f25427ca04d31]]></id>
<requestdate>2013-11-13T08:53:47-00:00</requestdate>
<vehicle interest="buy" status="used">
	<year><![CDATA[2011]]></year>
	<make><![CDATA[Chevrolet]]></make>
	<model><![CDATA[Malibu]]></model>
	<vin><![CDATA[1G1ZB5EU9BF127056]]></vin>
	<stock><![CDATA[M1869A]]></stock>
	<trim><![CDATA[LS]]></trim>
	<doors><![CDATA[4 door]]></doors>
	<bodystyle><![CDATA[Sedan]]></bodystyle>
	<transmission><![CDATA[Automatic]]></transmission>
	<odometer status="unknown" units="mi"><![CDATA[91,122]]></odometer>
	<colorcombination>
		<interiorcolor><![CDATA[Grey]]></interiorcolor>
		<exteriorcolor><![CDATA[Blue]]></exteriorcolor>
	</colorcombination>
</vehicle>
</prospect>
</adf>
EOT;
?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>Chris Stanyon</title>
	</head>
	<body>
		
<?php  
$obj = SimpleXML_Load_String($xmlString, 'SimpleXMLElement', LIBXML_NOCDATA);

foreach ($obj->prospect->vehicle as $vehicle):		
	printf('<p>%s</p>', (string)$vehicle->year);
	printf('<p>%s</p>', (string)$vehicle->model);
endforeach;
?>

	</body>
</html>

Open in new window

0
 
LVL 42

Expert Comment

by:Chris Stanyon
Comment Utility
You beat me to it posting your XML with CDATA, but I've just tested it using the script above and it still works fine.
0
 
LVL 1

Author Comment

by:tjyoung
Comment Utility
I was afraid of that really. The incoming xml is coming in as an email that I'm piping to my script. I'm guessing that may be the issue then. Its so convoluted I was hoping not to bother anyone with it and I totally understand if its too complicated to troubleshoot. I've removed some DB connection info/twilio info. 5.2XX is the php I'm using/stuck with.

I've posted the works below just in case but I get it if its too out there to bother with:
#!/usr/bin/php -q
<?php
ob_start();


//database connection
// Connect to server and select database.
$db = mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


require_once('includes/rfc822_addresses.php');
require_once('includes/mime_parser.php');
require 'Services/Twilio.php';

$version = "2010-04-01";


$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
    $email .= fread($fd, 1024);
}
fclose($fd);
$mime=new mime_parser_class;
$mime->ignore_syntax_errors = 1;
$parameters=array(
	'Data'=>$email,
);
$mime->Decode($parameters, $decoded);
$fromName = $decoded[0]['ExtractedAddresses']['from:'][0]['name'];
$fromEmail = $decoded[0]['ExtractedAddresses']['from:'][0]['address'];
$toEmail = $decoded[0]['ExtractedAddresses']['to:'][0]['address'];
$toName = $decoded[0]['ExtractedAddresses']['to:'][0]['name'];
$subject = $decoded[0]['Headers']['subject:'];
$removeChars = array('<','>');
$messageID = str_replace($removeChars,'',$decoded[0]['Headers']['message-id:']);
$replyToID = str_replace($removeChars,'',$decoded[0]['Headers']['in-reply-to:']);
if(substr($decoded[0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Body'])){
$body = $decoded[0]['Body'];
} elseif(substr($decoded[0]['Parts'][0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Parts'][0]['Body'])) {
$body = $decoded[0]['Parts'][0]['Body'];
} elseif(substr($decoded[0]['Parts'][0]['Parts'][0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Parts'][0]['Parts'][0]['Body'])) {
$body = $decoded[0]['Parts'][0]['Parts'][0]['Body'];
}


$obj = SimpleXML_Load_String($body, 'SimpleXMLElement', LIBXML_NOCDATA);


foreach ($obj->prospect->vehicle as $vehicle)
{
    $interest = 	(string)$vehicle['interest'];
    $leadType =		(string)strtoupper($vehicle['status']);
    $year = 		(string)$vehicle->year;
    $make = 		(string)strtoupper($vehicle->make);
    $model = 		(string)strtoupper($vehicle->model);
    $vin = 			(string)strtoupper($vehicle->vin);
    $stock = 		(string)strtoupper($vehicle->stock);
    $trim = 		(string)strtoupper($vehicle->trim);
    $leadVehicle = 	(string)strtoupper($year." ".$make." ".$model." ".$trim." ".$stock);
    $leadCreated = 	date('Y-m-d H:i:s');
    $leadModified =	date('Y-m-d H:i:s');
}

foreach ($obj->prospect->customer->contact as $customer)
{
    $leadFirstName	 = 		(string)strtoupper($customer->name[0]);
    $leadLastName	 = 		(string)strtoupper($customer->name[1]);
    $leadEmail		 = 		(string)strtoupper($customer->email);
    $leadPhone		 = 		(string)$customer->phone;
    $leadAddress	= 		(string)strtoupper($customer->address->street);
    $leadCity	= 			(string)strtoupper($customer->address->city);
    $leadProvince	= 		(string)strtoupper($customer->address->regioncode);
    $leadPostal		= 		(string)strtoupper($customer->address->postalcode);
    
    
    $leadPhone = ereg_replace("[^0-9]", "", $leadPhone);
    
if($leadPhone != ""){
    
    if (strlen($leadPhone) < 8) {
		$leadPhone = '902'.$leadPhone;
		} else if (strlen($leadPhone > 10)){
		$leadPhone = substr($leadPhone, -10);
		}
	$leadPhone = preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $leadPhone);
}	

if( ($leadPhone != "") && ($leadEmail != "") ){
			$sms_contact = 'Ph: '.$leadPhone.' Email: '.$leadEmail;
		} else if ( ($leadPhone != "") && ($leadEmail == "") ){
			$sms_contact = 'Ph: '.$leadPhone;
		} else if ( ($leadPhone == "") && ($leadEmail != "") ){
			$sms_contact = 'Email: '.$leadEmail;
		}
}

if(($leadLastName == "x") || ($leadLastName == "X")){
	$leadLastName = "";
	}

foreach ($obj->prospect->customer->comments as $comment)
{
    $leadStatusComment	 =	mysql_real_escape_string(nl2br(trim($comment)));
}

foreach ($obj->prospect->vendor as $dealership)
{
    $dealer	 = 		(string)strtoupper($dealership->vendorname);
}

foreach ($obj->prospect->provider as $supplier)
{
    $supplier	 = 		(string)strtoupper($supplier->name);
}


//GET THE PROVIDER
$result = mysql_query("SELECT name, service FROM providers WHERE name = '$supplier' LIMIT 1");

if(mysql_num_rows($result) > 0){
	while ($row = mysql_fetch_assoc($result)) {
	$provider_name = $row["name"];
	$lead = $row["service"];
	}
	}
	
	
//TEMP DEALER FOR TESTING
$result = mysql_query("SELECT id FROM user WHERE company_name = 'Steele Subaru' AND parent_user_id = 0 LIMIT 1");

if(mysql_num_rows($result) > 0){
	while ($row = mysql_fetch_assoc($result)) {
	$id = $row["id"];
	
	$sql="INSERT INTO leads(user_id,parent_id,lead,leadFirstName,leadLastName,leadAddress,leadCity,leadProvince,leadPostal,leadPhone,leadEmail,leadType,leadVehicle,leadStatusComment,leadCreated,leadModified)VALUES('$id','$id','$lead','$leadFirstName','$leadLastName','$leadAddress','$leadCity','$leadProvince','$leadPostal','$leadPhone','$leadEmail','$leadType','$leadVehicle','$leadStatusComment','$leadCreated','$leadModified')";
	mysql_query($sql);
	$lead_id = mysql_insert_id();
	}

	$result = mysql_query("SELECT * FROM appraisers WHERE parent_id = '$id' AND status = 1");
	while ($row = mysql_fetch_assoc($result)) {
		$to = $row["manager_phone"];
		$sms_message = 'New Chat Lead ID# '.$lead_id.': '.$leadFirstName.' '.$leadLastName.' is looking for a '.$leadType.' '.$leadVehicle.' '.$sms_contact;
		$client = new Services_Twilio($AccountSid, $AuthToken);	
		$sms = $client->account->sms_messages->create($dealerphone,$to,$sms_message);
	}	

}
ob_end_clean();

Open in new window

0
 
LVL 42

Expert Comment

by:Chris Stanyon
Comment Utility
OK. Start simple. Add this to line 42 of my script and run it as it is:

var_dump($obj);

At least this way we can check that the XML part of things is working first, without all the other stuff clouding the issue
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
PHP 5.2 is not good.  Not supported any more, not even for security fixes.  You probably want to get to 5.4+ at least.

I also found no trouble using the CDATA sample.  I'll look at the new code set and post back in a few minutes.
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
I think I would put this at line 25.  If you do that and you can post the output here, it might be helpful.  Then we would be working on the same input you're working on!

var_dump($email);
0
 
LVL 1

Author Comment

by:tjyoung
Comment Utility
This $obj was fine using Chris's but am going to plug the var_dump into the pipe and see what transpires. Just a second or two.
Many thanks by the way.

object(SimpleXMLElement)#1 (1) { ["prospect"]=> object(SimpleXMLElement)#2 (7) { ["@attributes"]=> array(1) { ["status"]=> string(3) "new" } ["id"]=> string(32) "50aa9ada0a0d0aee137f25427ca04d31" ["requestdate"]=> string(25) "2013-11-13T08:53:47-00:00" ["vehicle"]=> object(SimpleXMLElement)#3 (17) { ["@attributes"]=> array(2) { ["interest"]=> string(3) "buy" ["status"]=> string(4) "used" } ["year"]=> string(4) "2011" ["make"]=> string(9) "Chevrolet" ["model"]=> string(6) "Malibu" ["vin"]=> string(17) "1G1ZB5EU9BF127056" ["stock"]=> string(6) "M1869A" ["trim"]=> string(2) "LS" ["doors"]=> string(6) "4 door" ["bodystyle"]=> string(5) "Sedan" ["transmission"]=> string(9) "Automatic" ["odometer"]=> string(6) "91,122" ["colorcombination"]=> object(SimpleXMLElement)#7 (3) { ["interiorcolor"]=> string(4) "Grey" ["exteriorcolor"]=> string(4) "Blue" ["preference"]=> string(1) "1" } ["imagetag"]=> string(67) "http://images.dealer.com/0247/62beb281acc4a040603853ca74b83d54x.jpg" ["price"]=> string(4) "9988" ["pricecomments"]=> object(SimpleXMLElement)#8 (0) { } ["option"]=> array(19) { [0]=> object(SimpleXMLElement)#9 (2) { ["optionname"]=> string(12) "AM/FM Stereo" ["weighting"]=> object(SimpleXMLElement)#29 (0) { } } [1]=> object(SimpleXMLElement)#10 (2) { ["optionname"]=> string(16) "Air Conditioning" ["weighting"]=> object(SimpleXMLElement)#30 (0) { } } [2]=> object(SimpleXMLElement)#11 (2) { ["optionname"]=> string(12) "Alloy Wheels" ["weighting"]=> object(SimpleXMLElement)#31 (0) { } } [3]=> object(SimpleXMLElement)#12 (2) { ["optionname"]=> string(22) "Anti-Lock Brakes (ABS)" ["weighting"]=> object(SimpleXMLElement)#32 (0) { } } [4]=> object(SimpleXMLElement)#13 (2) { ["optionname"]=> string(10) "Anti-Theft" ["weighting"]=> object(SimpleXMLElement)#33 (0) { } } [5]=> object(SimpleXMLElement)#14 (2) { ["optionname"]=> string(20) "Auxiliary 12v Outlet" ["weighting"]=> object(SimpleXMLElement)#34 (0) { } } [6]=> object(SimpleXMLElement)#15 (2) { ["optionname"]=> string(12) "Bucket Seats" ["weighting"]=> object(SimpleXMLElement)#35 (0) { } } [7]=> object(SimpleXMLElement)#16 (2) { ["optionname"]=> string(9) "CD Player" ["weighting"]=> object(SimpleXMLElement)#36 (0) { } } [8]=> object(SimpleXMLElement)#17 (2) { ["optionname"]=> string(18) "Child-Safety Locks" ["weighting"]=> object(SimpleXMLElement)#37 (0) { } } [9]=> object(SimpleXMLElement)#18 (2) { ["optionname"]=> string(14) "Cloth Interior" ["weighting"]=> object(SimpleXMLElement)#38 (0) { } } [10]=> object(SimpleXMLElement)#19 (2) { ["optionname"]=> string(14) "Cruise Control" ["weighting"]=> object(SimpleXMLElement)#39 (0) { } } [11]=> object(SimpleXMLElement)#20 (2) { ["optionname"]=> string(18) "Driver Side Airbag" ["weighting"]=> object(SimpleXMLElement)#40 (0) { } } [12]=> object(SimpleXMLElement)#21 (2) { ["optionname"]=> string(19) "Intermittent Wipers" ["weighting"]=> object(SimpleXMLElement)#41 (0) { } } [13]=> object(SimpleXMLElement)#22 (2) { ["optionname"]=> string(13) "Keyless Entry" ["weighting"]=> object(SimpleXMLElement)#42 (0) { } } [14]=> object(SimpleXMLElement)#23 (2) { ["optionname"]=> string(17) "Navigation System" ["weighting"]=> object(SimpleXMLElement)#43 (0) { } } [15]=> object(SimpleXMLElement)#24 (2) { ["optionname"]=> string(16) "Passenger Airbag" ["weighting"]=> object(SimpleXMLElement)#44 (0) { } } [16]=> object(SimpleXMLElement)#25 (2) { ["optionname"]=> string(11) "Power Locks" ["weighting"]=> object(SimpleXMLElement)#45 (0) { } } [17]=> object(SimpleXMLElement)#26 (2) { ["optionname"]=> string(13) "Power Mirrors" ["weighting"]=> object(SimpleXMLElement)#46 (0) { } } [18]=> object(SimpleXMLElement)#27 (2) { ["optionname"]=> string(10) "Power Seat" ["weighting"]=> object(SimpleXMLElement)#47 (0) { } } } ["comments"]=> object(SimpleXMLElement)#28 (0) { } } ["customer"]=> object(SimpleXMLElement)#4 (2) { ["contact"]=> object(SimpleXMLElement)#48 (4) { ["name"]=> array(2) { [0]=> string(4) "Todd" [1]=> string(7) "Testing" } ["email"]=> string(24) "tthompson@steeleauto.com" ["phone"]=> string(10) "9024543060" ["address"]=> object(SimpleXMLElement)#49 (5) { ["street"]=> array(2) { [0]=> object(SimpleXMLElement)#50 (1) { ["@attributes"]=> array(1) { ["line"]=> string(1) "1" } } [1]=> object(SimpleXMLElement)#51 (1) { ["@attributes"]=> array(1) { ["line"]=> string(1) "2" } } } ["city"]=> object(SimpleXMLElement)#52 (0) { } ["regioncode"]=> object(SimpleXMLElement)#53 (0) { } ["postalcode"]=> object(SimpleXMLElement)#54 (0) { } ["country"]=> object(SimpleXMLElement)#55 (0) { } } } ["comments"]=> string(47) "Just testing integration from AutoTrader now :)" } ["vendor"]=> object(SimpleXMLElement)#5 (2) { ["vendorname"]=> string(11) "Steele Cars" ["contact"]=> object(SimpleXMLElement)#56 (4) { ["name"]=> array(2) { [0]=> object(SimpleXMLElement)#57 (1) { ["@attributes"]=> array(1) { ["part"]=> string(5) "first" } } [1]=> object(SimpleXMLElement)#58 (1) { ["@attributes"]=> array(1) { ["part"]=> string(4) "last" } } } ["email"]=> string(20) "sales@steelecars.com" ["phone"]=> string(12) "902-462-6600" ["address"]=> object(SimpleXMLElement)#59 (5) { ["street"]=> array(2) { [0]=> string(18) "15 somewhere Court" [1]=> object(SimpleXMLElement)#60 (1) { ["@attributes"]=> array(1) { ["line"]=> string(1) "2" } } } ["city"]=> string(9) "DARTMOUTH" ["regioncode"]=> string(2) "NS" ["postalcode"]=> string(7) "B2W 0K3" ["country"]=> string(2) "CA" } } } ["provider"]=> object(SimpleXMLElement)#6 (6) { ["name"]=> string(10) "Dealer.com" ["service"]=> string(31) "Test Drive - Dealer.Com Website" ["url"]=> string(14) "www.dealer.com" ["email"]=> string(18) "support@dealer.com" ["phone"]=> string(12) "888-895-2994" ["contact"]=> object(SimpleXMLElement)#61 (4) { ["name"]=> string(18) "Dealer.com Support" ["email"]=> string(18) "support@dealer.com" ["phone"]=> string(12) "888-895-2994" ["address"]=> object(SimpleXMLElement)#62 (5) { ["street"]=> string(15) "1 Howard Street" ["city"]=> string(10) "Burlington" ["regioncode"]=> string(2) "VT" ["postalcode"]=> string(5) "05401" ["country"]=> string(2) "US" } } } } }

2011

Malibu

Open in new window

0
 
LVL 1

Author Comment

by:tjyoung
Comment Utility
I sent through an email with the ADF problem in and used the mail php function to email me back the $email variable which it did (not sure how else to get at the info when using the pipe).

As an email I got back everything include the mail headers etc shown below:
From tthompson@myemail.com Wed Nov 13 12:07:16 2013
Received: from blk-224-134-210.eastlink.ca ([24.224.134.210]:64434 helo=[10.7.24.48])
	by server.myemail.com with esmtpa (Exim 4.80.1)
	(envelope-from <tthompson@myemail.com>)
	id 1VgcyK-0002wd-Kx
	for mazdachat@myemail.com; Wed, 13 Nov 2013 12:07:16 -0400
Message-Id: <D110B7CE-51EB-4010-9259-735EF3576097@steeleauto.ca>
From: Todd Thompson <tthompson@myemail.com>
To: mazdachat@myemail.com
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0 (Apple Message framework v936)
Subject: testing
Date: Wed, 13 Nov 2013 12:07:18 -0400
X-Mailer: Apple Mail (2.936)

<?xml version="1.0"?>
<?ADF version="1.0"?>
<adf>
<prospect status="new">
<id sequence="1" source="Dealer.com"><! 
[CDATA[50aa9ada0a0d0aee137f25427ca04d31]]></id>
<requestdate>2013-11-13T08:53:47-00:00</requestdate>
<vehicle interest="buy" status="used">
<year><![CDATA[2011]]></year>
<make><![CDATA[Chevrolet]]></make>
<model><![CDATA[Malibu]]></model>
<vin><![CDATA[1G1ZB5EU9BF127056]]></vin>
<stock><![CDATA[M1869A]]></stock>
<trim><![CDATA[LS]]></trim>
<doors><![CDATA[4 door]]></doors>
<bodystyle><![CDATA[Sedan]]></bodystyle>
<transmission><![CDATA[Automatic]]></transmission>
<odometer status="unknown" units="mi"><![CDATA[91,122]]></odometer>
<colorcombination>
<interiorcolor><![CDATA[Grey]]></interiorcolor>
<exteriorcolor><![CDATA[Blue]]></exteriorcolor>
<preference>1</preference>
</colorcombination>
<imagetag><![CDATA[http://images.dealer.com/0247/62beb281acc4a040603853ca74b83d54x.jpg 
]]></imagetag>
<price type="quote" currency="CAD"><![CDATA[9988]]></price>
<pricecomments><![CDATA[]]></pricecomments>
<option>
<optionname><![CDATA[AM/FM Stereo]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Air Conditioning]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Alloy Wheels]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Anti-Lock Brakes (ABS)]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Anti-Theft]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Auxiliary 12v Outlet]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Bucket Seats]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[CD Player]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Child-Safety Locks]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Cloth Interior]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Cruise Control]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Driver Side Airbag]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Intermittent Wipers]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Keyless Entry]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Navigation System]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Passenger Airbag]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Power Locks]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Power Mirrors]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Power Seat]]></optionname>
<weighting></weighting>
</option>
<comments><![CDATA[]]></comments>
</vehicle>
<customer>
<contact>
<name part="first"><![CDATA[Todd]]></name>
<name part="last"><![CDATA[Testing]]></name>
<email preferredcontact="1"><![CDATA[tthompson@myemail.com]]></email>
<phone type="voice" time="nopreference"><![CDATA[9024543060]]></phone>
<address>
<street line="1"><![CDATA[]]></street>
<street line="2"><![CDATA[]]></street>
<city><![CDATA[]]></city>
<regioncode><![CDATA[]]></regioncode>
<postalcode><![CDATA[]]></postalcode>
<country><![CDATA[]]></country>
</address>
</contact>
<comments><![CDATA[Just testing integration from AutoTrader now :)]]></ 
comments>
</customer>
<vendor>
<vendorname><![CDATA[Steele cars]]></vendorname>
<contact>
<name part="first"><![CDATA[]]></name>
<name part="last"><![CDATA[]]></name>
<email><![CDATA[sales@steelecars.com]]></email>
<phone type="voice" time="nopreference"><![CDATA[902-462-6600]]></phone>
<address>
<street line="1"><![CDATA[15 Somehwere Court]]></street>
<street line="2"><![CDATA[]]></street>
<city><![CDATA[DARTMOUTH]]></city>
<regioncode><![CDATA[NS]]></regioncode>
<postalcode><![CDATA[B2W 0K3]]></postalcode>
<country><![CDATA[CA]]></country>
</address>
</contact>
</vendor>
<provider>
<name part="full"><![CDATA[Dealer.com]]></name>
<service><![CDATA[Test Drive - Dealer.Com Website]]></service>
<url><![CDATA[www.dealer.com]]></url>
<email><![CDATA[support@dealer.com]]></email>
<phone type="voice"><![CDATA[888-895-2994]]></phone>
<contact>
<name part="full"><![CDATA[Dealer.com Support]]></name>
<email><![CDATA[support@dealer.com]]></email>
<phone type="voice" time="day"><![CDATA[888-895-2994]]></phone>
<address>
<street line="1"><![CDATA[1 Howard Street]]></street>
<city><![CDATA[Burlington]]></city>
<regioncode><![CDATA[VT]]></regioncode>
<postalcode><![CDATA[05401]]></postalcode>
<country><![CDATA[US]]></country>
</address>
</contact>
</provider>
</prospect>
</adf>

Open in new window

0
 
LVL 1

Author Comment

by:tjyoung
Comment Utility
If I have it email me back the $body variable, I receive back an email with just the xml I originally sent, so I seem to have a $body variable that represents the xml.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 42

Expert Comment

by:Chris Stanyon
Comment Utility
In your pipe script, try var_dumping the $obj variable on line 49. That will give you some idea of what's coming into your script.
0
 
LVL 1

Author Comment

by:tjyoung
Comment Utility
I just tried sending myself back the $obj using the mail function and I get nothing back with either file (not sure what I should expect in that case though?).

I did however try it with a couple variables like 'Year' and 'Make' emailing those back and with the problem free xml I get back the appropriate response, with the trouble one, I get nothing back just a blank email.
0
 
LVL 1

Author Comment

by:tjyoung
Comment Utility
Sorry to keep posting, just thought this could be helpful:

Just got in yet another provider... no CDATA everywhere and it seems fine as well. Posted sample below:
<adf>
<prospect>
<id sequence="1" source="ChryslerCanada">1811532</id>
<requestdate>2013-11-13T14:59:10.053</requestdate>
<vehicle interest="buy" status="used">
<year>2012</year>
<make>GMC</make>
<model>Sierra 1500</model>
<vin>3GTP2WE74CG273055</vin>
<trim>SLT</trim>
<doors>4 door</doors>
<bodystyle>Pickup</bodystyle>
<colorcombination>
<interiorcolor>Ebony/Light Titanium</interiorcolor>
<exteriorcolor>White Diamond Tri-Coat</exteriorcolor>
<preference>1</preference>
</colorcombination>
<imagetag></imagetag>
<option>
<optionname>4th Door</optionname>
</option>
<option>
<optionname>ABS Brakes</optionname>
</option>
<option>
<optionname>AM/FM Stereo</optionname>
</option>
<option>
<optionname>Air Conditioning</optionname>
</option>
<option>
<optionname>Alarm</optionname>
</option>
<option>
<optionname>Alloy Wheels</optionname>
</option>
<option>
<optionname>Anti-Theft</optionname>
</option>
<option>
<optionname>Auxiliary 12v Outlet</optionname>
</option>
<option>
<optionname>Auxiliary Audio Jack</optionname>
</option>
<option>
<optionname>Backup Sensor</optionname>
</option>
<option>
<optionname>Bluetooth</optionname>
</option>
<option>
<optionname>Box Liner</optionname>
</option>
<option>
<optionname>Bucket Seats</optionname>
</option>
<option>
<optionname>CD Player</optionname>
</option>
<option>
<optionname>Child-Safety Locks</optionname>
</option>
<option>
<optionname>Climate Control</optionname>
</option>
<option>
<optionname>Cruise Control</optionname>
</option>
<option>
<optionname>DVD Entertainment System</optionname>
</option>
<option>
<optionname>Driver Side Air Bag</optionname>
</option>
</vehicle>
<customer>
<contact>
<name part="first">Lance</name>
<name part="last">thelead</name>
<email>thelead@hotmail.com</email>
<phone type="voice" time="nopreference">9029633396</phone>
<phone type="cellphone" time="nopreference" />
<phone type="voice" time="nopreference" />
<address>
<street line="1"> </street>
<street line="2" />
<city />
<regioncode />
<postalcode>C0A1N0</postalcode>
</address>
</contact>
<comments><![CDATA[Hello, I have a 2005 GMC sierra SLT extended cab. It has the Z71 towing package, black leather, two tone green and tan paint on the exterior. Truck has 150000 km on her and was just quoted at a local gm dealership for $8000. Just wondering what your best price is on trade? Thanks, I prefer that you email me as well since i'm rarely available at my phone number.]]></comments>
</customer>
<vendor>
<id>C1520</id>
<vendorname>Halifax</vendorname>
<contact>
<name part="full">Halifax Chrysler Dodge</name>
<email>inquiry@dealer.com</email>
<phone type="voice" time="nopreference">9024555555</phone>
<address>
<street line="1">12 Lakelands Boulevard</street>
<street line="2" />
<city>Halifax</city>
<regioncode>NS</regioncode>
<postalcode>B3S1S</postalcode>
</address>
</contact>
</vendor>
<provider>
<name part="full" type="business">Chrysler Dealer Website - Request More Info</name>
</provider>
</prospect>
</adf>

Open in new window

0
 
LVL 1

Author Comment

by:tjyoung
Comment Utility
That last example snapped right in to the DB etc. perfectly and from a different provider. Has something to do with the CDATA everywhere I'm guessing? Way to removed it all when one comes in? Could be a dumb idea... just throwing it out there.
0
 
LVL 42

Expert Comment

by:Chris Stanyon
Comment Utility
You could potentially remove it with some clever Regular Expressions, but you're probably better off trying to figure out why it's breaking in the first place. I can't replicate your problem, and the code I've tested using your data (including all the CDATA) works fine.

Did you get to var_dump the $obj in your script?
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
The string posted here has a syntax error.  Look at line 21 and 22.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28292950.html#a39645171

This is only a guess, but you might try changing the way this is read from stdin:

OLD:
while (!feof($fd)) {
    $email .= fread($fd, 1024);
}

TRY:
while (!feof($fd)) {
    $email .= fread($fd, 8192);
}
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
See also line 137 and 138 - unwanted line breaks there, too.  With those corrected, the XML is usable.  I was unable to fix those lines programmatically, so I fixed them in a text editor.  I don't understand why there was a problem doing it in PHP.  I'll try to show you what I did in a moment.
0
 
LVL 1

Author Comment

by:tjyoung
Comment Utility
Did the change to this:
while (!feof($fd)) {
    $email .= fread($fd, 8192);
}

to no avail. I've now tried piping in any additional leads from Chrysler and see if going in directly makes a difference. Have to wait for a lead or two though...
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Please see: http://www.laprbass.com/RAY_temp_tjyoung.php
Outputs: 2011 Chevrolet Malibu

<?php // RAY_temp_mayo.php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
echo '<pre>';

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28292950.html#a39645171
// MADE A MANUAL REPAIR OF SOME DAMAGE IN THE CDATA TAGS (UNWANTED LINE BREAKS)

$email = <<<EOD
From tthompson@myemail.com Wed Nov 13 12:07:16 2013
Received: from blk-224-134-210.eastlink.ca ([24.224.134.210]:64434 helo=[10.7.24.48])
	by server.myemail.com with esmtpa (Exim 4.80.1)
	(envelope-from <tthompson@myemail.com>)
	id 1VgcyK-0002wd-Kx
	for mazdachat@myemail.com; Wed, 13 Nov 2013 12:07:16 -0400
Message-Id: <D110B7CE-51EB-4010-9259-735EF3576097@steeleauto.ca>
From: Todd Thompson <tthompson@myemail.com>
To: mazdachat@myemail.com
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0 (Apple Message framework v936)
Subject: testing
Date: Wed, 13 Nov 2013 12:07:18 -0400
X-Mailer: Apple Mail (2.936)

<?xml version="1.0"?>
<?ADF version="1.0"?>
<adf>
<prospect status="new">
<id sequence="1" source="Dealer.com"><![CDATA[50aa9ada0a0d0aee137f25427ca04d31]]></id>
<requestdate>2013-11-13T08:53:47-00:00</requestdate>
<vehicle interest="buy" status="used">
<year><![CDATA[2011]]></year>
<make><![CDATA[Chevrolet]]></make>
<model><![CDATA[Malibu]]></model>
<vin><![CDATA[1G1ZB5EU9BF127056]]></vin>
<stock><![CDATA[M1869A]]></stock>
<trim><![CDATA[LS]]></trim>
<doors><![CDATA[4 door]]></doors>
<bodystyle><![CDATA[Sedan]]></bodystyle>
<transmission><![CDATA[Automatic]]></transmission>
<odometer status="unknown" units="mi"><![CDATA[91,122]]></odometer>
<colorcombination>
<interiorcolor><![CDATA[Grey]]></interiorcolor>
<exteriorcolor><![CDATA[Blue]]></exteriorcolor>
<preference>1</preference>
</colorcombination>
<imagetag><![CDATA[http://images.dealer.com/0247/62beb281acc4a040603853ca74b83d54x.jpg
]]></imagetag>
<price type="quote" currency="CAD"><![CDATA[9988]]></price>
<pricecomments><![CDATA[]]></pricecomments>
<option>
<optionname><![CDATA[AM/FM Stereo]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Air Conditioning]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Alloy Wheels]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Anti-Lock Brakes (ABS)]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Anti-Theft]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Auxiliary 12v Outlet]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Bucket Seats]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[CD Player]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Child-Safety Locks]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Cloth Interior]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Cruise Control]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Driver Side Airbag]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Intermittent Wipers]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Keyless Entry]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Navigation System]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Passenger Airbag]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Power Locks]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Power Mirrors]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Power Seat]]></optionname>
<weighting></weighting>
</option>
<comments><![CDATA[]]></comments>
</vehicle>
<customer>
<contact>
<name part="first"><![CDATA[Todd]]></name>
<name part="last"><![CDATA[Testing]]></name>
<email preferredcontact="1"><![CDATA[tthompson@myemail.com]]></email>
<phone type="voice" time="nopreference"><![CDATA[9024543060]]></phone>
<address>
<street line="1"><![CDATA[]]></street>
<street line="2"><![CDATA[]]></street>
<city><![CDATA[]]></city>
<regioncode><![CDATA[]]></regioncode>
<postalcode><![CDATA[]]></postalcode>
<country><![CDATA[]]></country>
</address>
</contact>
<comments><![CDATA[Just testing integration from AutoTrader now :)]]></comments>
</customer>
<vendor>
<vendorname><![CDATA[Steele cars]]></vendorname>
<contact>
<name part="first"><![CDATA[]]></name>
<name part="last"><![CDATA[]]></name>
<email><![CDATA[sales@steelecars.com]]></email>
<phone type="voice" time="nopreference"><![CDATA[902-462-6600]]></phone>
<address>
<street line="1"><![CDATA[15 Somehwere Court]]></street>
<street line="2"><![CDATA[]]></street>
<city><![CDATA[DARTMOUTH]]></city>
<regioncode><![CDATA[NS]]></regioncode>
<postalcode><![CDATA[B2W 0K3]]></postalcode>
<country><![CDATA[CA]]></country>
</address>
</contact>
</vendor>
<provider>
<name part="full"><![CDATA[Dealer.com]]></name>
<service><![CDATA[Test Drive - Dealer.Com Website]]></service>
<url><![CDATA[www.dealer.com]]></url>
<email><![CDATA[support@dealer.com]]></email>
<phone type="voice"><![CDATA[888-895-2994]]></phone>
<contact>
<name part="full"><![CDATA[Dealer.com Support]]></name>
<email><![CDATA[support@dealer.com]]></email>
<phone type="voice" time="day"><![CDATA[888-895-2994]]></phone>
<address>
<street line="1"><![CDATA[1 Howard Street]]></street>
<city><![CDATA[Burlington]]></city>
<regioncode><![CDATA[VT]]></regioncode>
<postalcode><![CDATA[05401]]></postalcode>
<country><![CDATA[US]]></country>
</address>
</contact>
</provider>
</prospect>
</adf>

EOD;

// ISOLATE THE XML DOCUMENT
$signal = '<?xml';
$locate = strpos($email, $signal);
$xml    = substr($email, $locate);
$xml    = trim($xml);

// MAKE AN OBJECT
$obj = SimpleXML_Load_String($xml, 'SimpleXMLElement', LIBXML_NOCDATA);

// EXTRACT SOME INFORMATION
$veh = $obj->prospect->vehicle;
$yr  = $veh->year;
$mk  = $veh->make;
$mo  = $veh->model;

echo PHP_EOL . "$yr $mk $mo";

Open in new window

0
 
LVL 82

Assisted Solution

by:hielo
hielo earned 200 total points
Comment Utility
no CDATA everywhere and it seems fine as well.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28292950.html#a39645245
If you take that sample xml and change line 81 from:
<regioncode />

to:
<regioncode><![CDATA[]]></regioncode>

Does it work?  I noticed that your working examples that have CDATA actually contain data in between, but the problematic files contains empty CDATA nodes.  If the above empty CDATA causes the problems, then try replacing them first:
$obj = SimpleXML_Load_String( str_replace('<![CDATA[]]>','',$body), 'SimpleXMLElement', LIBXML_NOCDATA);

Open in new window

If the problem persists, try loading the xml using DOMDocument.  Thus, instead of:
$obj = SimpleXML_Load_String($body, 'SimpleXMLElement', LIBXML_NOCDATA);

Open in new window


try:
$obj = new DOMDocument();
$obj->loadXML($body,LIBXML_NOCDATA);

$obj = SimpleXML_Load_String( $obj->saveXML(), 'SimpleXMLElement');

Open in new window


Lastly, if all else fails, you can always try a regex:
$obj = SimpleXML_Load_String( preg_replace('#<!\[CDATA\[([\d\D]*?)\]\]>#','$1',$body), 'SimpleXMLElement', LIBXML_NOCDATA);

Open in new window

0
 
LVL 1

Author Comment

by:tjyoung
Comment Utility
I'm on it and will post back. Thanks very much for the additional input!
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 300 total points
Comment Utility
http://www.laprbass.com/RAY_temp_tjyoung.php

Please see line 196-201.  I still do not understand this completely.  I tried replacing PHP_EOL, "\n", "\r" and none of them worked.  But when I copied the bad tags and pasted them into the str_replace() code, the script was able to create the object and access the data.

<?php // RAY_temp_mayo.php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
echo '<pre>';

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28292950.html#a39645171
// MADE A MANUAL REPAIR OF SOME DAMAGE IN THE CDATA TAGS (UNWANTED LINE BREAKS)

$email = <<<EOD
From tthompson@myemail.com Wed Nov 13 12:07:16 2013
Received: from blk-224-134-210.eastlink.ca ([24.224.134.210]:64434 helo=[10.7.24.48])
	by server.myemail.com with esmtpa (Exim 4.80.1)
	(envelope-from <tthompson@myemail.com>)
	id 1VgcyK-0002wd-Kx
	for mazdachat@myemail.com; Wed, 13 Nov 2013 12:07:16 -0400
Message-Id: <D110B7CE-51EB-4010-9259-735EF3576097@steeleauto.ca>
From: Todd Thompson <tthompson@myemail.com>
To: mazdachat@myemail.com
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0 (Apple Message framework v936)
Subject: testing
Date: Wed, 13 Nov 2013 12:07:18 -0400
X-Mailer: Apple Mail (2.936)

<?xml version="1.0"?>
<?ADF version="1.0"?>
<adf>
<prospect status="new">
<id sequence="1" source="Dealer.com"><!
[CDATA[50aa9ada0a0d0aee137f25427ca04d31]]></id>
<requestdate>2013-11-13T08:53:47-00:00</requestdate>
<vehicle interest="buy" status="used">
<year><![CDATA[2011]]></year>
<make><![CDATA[Chevrolet]]></make>
<model><![CDATA[Malibu]]></model>
<vin><![CDATA[1G1ZB5EU9BF127056]]></vin>
<stock><![CDATA[M1869A]]></stock>
<trim><![CDATA[LS]]></trim>
<doors><![CDATA[4 door]]></doors>
<bodystyle><![CDATA[Sedan]]></bodystyle>
<transmission><![CDATA[Automatic]]></transmission>
<odometer status="unknown" units="mi"><![CDATA[91,122]]></odometer>
<colorcombination>
<interiorcolor><![CDATA[Grey]]></interiorcolor>
<exteriorcolor><![CDATA[Blue]]></exteriorcolor>
<preference>1</preference>
</colorcombination>
<imagetag><![CDATA[http://images.dealer.com/0247/62beb281acc4a040603853ca74b83d54x.jpg
]]></imagetag>
<price type="quote" currency="CAD"><![CDATA[9988]]></price>
<pricecomments><![CDATA[]]></pricecomments>
<option>
<optionname><![CDATA[AM/FM Stereo]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Air Conditioning]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Alloy Wheels]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Anti-Lock Brakes (ABS)]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Anti-Theft]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Auxiliary 12v Outlet]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Bucket Seats]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[CD Player]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Child-Safety Locks]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Cloth Interior]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Cruise Control]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Driver Side Airbag]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Intermittent Wipers]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Keyless Entry]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Navigation System]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Passenger Airbag]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Power Locks]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Power Mirrors]]></optionname>
<weighting></weighting>
</option>
<option>
<optionname><![CDATA[Power Seat]]></optionname>
<weighting></weighting>
</option>
<comments><![CDATA[]]></comments>
</vehicle>
<customer>
<contact>
<name part="first"><![CDATA[Todd]]></name>
<name part="last"><![CDATA[Testing]]></name>
<email preferredcontact="1"><![CDATA[tthompson@myemail.com]]></email>
<phone type="voice" time="nopreference"><![CDATA[9024543060]]></phone>
<address>
<street line="1"><![CDATA[]]></street>
<street line="2"><![CDATA[]]></street>
<city><![CDATA[]]></city>
<regioncode><![CDATA[]]></regioncode>
<postalcode><![CDATA[]]></postalcode>
<country><![CDATA[]]></country>
</address>
</contact>
<comments><![CDATA[Just testing integration from AutoTrader now :)]]></
comments>
</customer>
<vendor>
<vendorname><![CDATA[Steele cars]]></vendorname>
<contact>
<name part="first"><![CDATA[]]></name>
<name part="last"><![CDATA[]]></name>
<email><![CDATA[sales@steelecars.com]]></email>
<phone type="voice" time="nopreference"><![CDATA[902-462-6600]]></phone>
<address>
<street line="1"><![CDATA[15 Somehwere Court]]></street>
<street line="2"><![CDATA[]]></street>
<city><![CDATA[DARTMOUTH]]></city>
<regioncode><![CDATA[NS]]></regioncode>
<postalcode><![CDATA[B2W 0K3]]></postalcode>
<country><![CDATA[CA]]></country>
</address>
</contact>
</vendor>
<provider>
<name part="full"><![CDATA[Dealer.com]]></name>
<service><![CDATA[Test Drive - Dealer.Com Website]]></service>
<url><![CDATA[www.dealer.com]]></url>
<email><![CDATA[support@dealer.com]]></email>
<phone type="voice"><![CDATA[888-895-2994]]></phone>
<contact>
<name part="full"><![CDATA[Dealer.com Support]]></name>
<email><![CDATA[support@dealer.com]]></email>
<phone type="voice" time="day"><![CDATA[888-895-2994]]></phone>
<address>
<street line="1"><![CDATA[1 Howard Street]]></street>
<city><![CDATA[Burlington]]></city>
<regioncode><![CDATA[VT]]></regioncode>
<postalcode><![CDATA[05401]]></postalcode>
<country><![CDATA[US]]></country>
</address>
</contact>
</provider>
</prospect>
</adf>

EOD;

// ISOLATE THE XML DOCUMENT
$signal = '<?xml';
$locate = strpos($email, $signal);
$xml    = substr($email, $locate);
$xml    = trim($xml);

// REPAIR THE DAMAGED TAGS (I DO NOT UNDERSTAND WHAT END-OF-LINE CHARACTER IS IN PLAY HERE)
$xml = str_replace('<!
[', '<![', $xml);

$xml = str_replace('</
', '</', $xml);

// MAKE AN OBJECT
$obj = SimpleXML_Load_String($xml, 'SimpleXMLElement', LIBXML_NOCDATA);

// EXTRACT SOME INFORMATION
$veh = $obj->prospect->vehicle;
$yr  = $veh->year;
$mk  = $veh->make;
$mo  = $veh->model;

echo PHP_EOL . "$yr $mk $mo";

Open in new window

0
 
LVL 1

Author Closing Comment

by:tjyoung
Comment Utility
This has been a bit of a cluster since the beginning so I very much appreciate any/all feedback as bits and pieces helped steer me/educate me to at least getting to something that worked after weeks.

In the end I implemented some of the practices above, and in my case the pipe script was coming in on a separate server(couldn't pipe on the actual main server) which upon receiving the incoming email, would connect mysql remotely to the other server and insert the info. One thing was the php versions weren't the same on both machines which made me wonder and I was questioning the connection dependability.

So ended up using curl to post the data when it came in to a script on the main server and do the insertions etc. there. So far... I'm not getting any errors. Been about 30 or so incoming pipes from real world submissions. Was getting errors in 1 out of 7... so maybe that got it.

Again, thanks as always for the help and sorry for the delay as I didn't have much to add till I at least got something going.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 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

13 Experts available now in Live!

Get 1:1 Help Now