Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert ASP with XML example to PHP with XML

Status
Not open for further replies.

ericaalicen

Programmer
Dec 20, 2001
53
US
I'm in way over my head. I code in coldfusion and have had a project dropped in my lap that requires me to send an xmlRequest in PHP and the example code I've been given is in ASP. This is the sample code, I've changed the url for privacy protection.

Code:
<%@ Language=vbScript%>
<%
Dim xmlRequest, xmlHttp

xmlRequest = "xmlRequest=<EstimateRequest><ReferralCode>3</ReferralCode><PrimaryContact>
<Email>hfieger@indigio.com</Email><FirstName>Henry</FirstName><LastName>
Fieger</LastName><PrimaryPhoneType>H</PrimaryPhoneType>
<PreferredContactTime>A</PreferredContactTime><HomePhone>3035551234
</HomePhone><WorkPhone>2223334444</WorkPhone><WorkPhoneExt>112
</WorkPhoneExt><CellPhone>2223334444</CellPhone><FaxPhone>2223334444
</FaxPhone></PrimaryContact><PickupAddress><Address1>410 17th St</Address1><Address2></Address2><City>Denver</City><State>CO</State>
<Zip>80202</Zip></PickupAddress><MoveDetails><PickupZip>80202</PickupZip>
<DeliveryZip>80110</DeliveryZip><MoveDate>5/1/2004</MoveDate><DwellingType>
H3</DwellingType><AmountOfFurnishings>M</AmountOfFurnishings>
<PickupShuttle>Y</PickupShuttle><DeliveryShuttle>N</DeliveryShuttle>
</MoveDetails><EstimateDetails><HasVehicles>Y</HasVehicles>
<RequestedEstimateDate>3D</RequestedEstimateDate>
<RequestedEstimateTimeOfDay>A</RequestedEstimateTimeOfDay><SpecialtyItems>
Hello</SpecialtyItems><Comments>World</Comments></EstimateDetails>
</EstimateRequest>"

Set xmlHttp = server.Createobject("MSXML2.ServerxmlHttp")

xmlHttp.Open "POST","[URL unfurl="true"]http://url.url.com/RAE/RequestAnEstimate.asmx/[/URL]
SendEstimateRequestXmlString", False
xmlHttp.setRequestHeader "Content-Type", "application/x-[URL unfurl="true"]www-form-urlencoded"[/URL]
xmlHttp.send xmlRequest

Response.ContentType = "text/xml"
Response.Write xmlHttp.responsexml.xml

Set xmlHttp = Nothing
%>

And this is what I've done in my weak attempt to convert to PHP.

Code:
<?php
Dim xmlRequest, xmlHttp;

xmlRequest = "xmlRequest=<EstimateRequest><ReferralCode>3</ReferralCode><PrimaryContact>
<Email>$myrow[Email]</Email><FirstName>$myrow[FirstN]</FirstName><LastName>
$myrow[LastN]</LastName><PrimaryPhoneType>H</PrimaryPhoneType>
<PreferredContactTime></PreferredContactTime><HomePhone>$myrow[Area]$myrow
[Pre]$myrow[Phone]</HomePhone><WorkPhone>$myrow[AreaW]$myrow[PreW]$myrow
[PhoneW]</WorkPhone><WorkPhoneExt></WorkPhoneExt><CellPhone></CellPhone>
<FaxPhone></FaxPhone></PrimaryContact><PickupAddress><Address1></Address1>
<Address2></Address2><City>$myrow[CityOrg]</City><State>$myrow[StateOrg]
</State><Zip>$myrow[ZipOrg]</Zip></PickupAddress><MoveDetails><PickupZip>
$myrow[ZipOrg]</PickupZip><DeliveryZip>$myrow[ZipDes]</DeliveryZip>
<MoveDate></MoveDate><DwellingType></DwellingType><AmountOfFurnishings>
</AmountOfFurnishings><PickupShuttle></PickupShuttle><DeliveryShuttle>
</DeliveryShuttle></MoveDetails><EstimateDetails><HasVehicles>
</HasVehicles><RequestedEstimateDate></RequestedEstimateDate>
<RequestedEstimateTimeOfDay></RequestedEstimateTimeOfDay><SpecialtyItems>
</SpecialtyItems><Comments>Trailer Length:$myrow[Length] ft. Quote Amount:\$$myrow[TotalCost] Comments:$myrow[Notes]</Comments></EstimateDetails></EstimateRequest>";

Set xmlHttp = server.Createobject("MSXML2.ServerxmlHttp");

xmlHttp.Open "POST","[URL unfurl="true"]http://url.url.com/RAE/RequestAnEstimate.asmx/[/URL]
SendEstimateRequestXmlString", False;
xmlHttp.setRequestHeader "Content-Type", "application/x-[URL unfurl="true"]www-form-urlencoded";[/URL]
xmlHttp.send xmlRequest;

$txt = "text/xml";
echo xmlHttp.responsexml.xml;

Set xmlHttp = Nothing;
?>

The server is supposed to respond back with something like:

Code:
<?xml version="1.0" encoding="utf-8" ?> 
- <EstimateResponse xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns="[URL unfurl="true"]http://url.url.com/RAE/">[/URL]
  <MoveId>979</MoveId> 
  <ErrorList /> 
  </EstimateResponse>

It's a different message if the code is not processed correctly, but same idea.

I don't know how to get the response. I imagine my code will crash even before I get that far at the moment.

Any pointers would be greatly appreciated.
 
your effort at converting appears more like vba or vb than php, i'm afraid!

you don't dimension or set variables in php with dim and set. just assign them a value and you're away. you can force a variable to a particular type by casting but outside of maths and some validation i've never needed to be too concerned with this.

it looks to me as though all you are trying to do is open an http connection to a remote server, bosh in some data through post and see what the result is - i don't think the contents of the data is important.

i would look in the php manual ( for the curl functions - i'd guess that these will do the job for you.

one other gotcha - you are referencing array elements within your string. normally you should enquote the element names but you are leaving them without quotes. this will work but will be generate errors (which are suppressable). There is also a performance penalty as php will be looking first for a constant with the same name as the element. if there is a constant so named, the variable reference will fail. i use single quotes around the element and curly braces around the variable so ...
Code:
echo "this is some text in double quotes and we are referencing this variable element: {$array['array_element']}";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top