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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing XML with CURL 1

Status
Not open for further replies.

Pic37

Technical User
Mar 28, 2010
4
US
I am having a problem parsing XML that is returned from a website that I use CURL to POST to. The value I am getting returned is a single character - STATUSCODE (1). The XML at website looks like:

<?xml version="1.0" encoding="" ?>
<TRUMPIA>
<STATUSCODE>1</STATUSCODE>
<MESSAGE>
<![CDATA[Query Success]]>
</MESSAGE>
<MEMBERCODE>
<![CDATA[12341234123412341234123412341234]]>
</MEMBERCODE>
<MEMBERDATA>
<FIRSTNAME>
<![CDATA[FIRST_NAME]]>
</FIRSTNAME>
<LASTNAME>
<![CDATA[LAST_NAME]]>
</LASTNAME>
<TOOLS>
<EMAIL VERIFY="1">
<![CDATA[email@email.com]]>
</EMAIL>
<MOBILEPHONE VERIFY="0">
<![CDATA[123123132123]]>
</MOBILEPHONE>
</TOOLS>
</MEMBERDATA>
</TRUMPIA>

If I send form to website it returns all data in string.

Here is the code that I have tried:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$path);
curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,"APIKEY=$apikey&ContactID=$contactid");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$retValue = curl_exec($ch);
echo $retValue;
curl_close($ch);
return $retValue;

Need to be able to access each individual field. Please help
 
if you are not getting back an xml string, and you are expecting one, then the issue is between you and the sending server. the curl looks fine.

however you might not see the output in the browser unless you wrap it in htmlspecialchars().

 
htmlspecialchars gives me the following:

<?xml version="1.0" encoding="UTF-8" ?> <TRUMPIA> <STATUSCODE>1</STATUSCODE> <MESSAGE><![CDATA[Query Success]]></MESSAGE> <CONTACTCODE><![CDATA[c0bXXXXXXXXXXb100aacefebb38f420]]></CONTACTCODE> <CONTACTDATA> <FIRSTNAME><![CDATA[Tom]]></FIRSTNAME> <LASTNAME><![CDATA[Pizzirilo]]></LASTNAME> <TOOLS> <EMAIL VERIFY="1"><![CDATA[tomp@advantagevalues.com]]></EMAIL> <MOBILEPHONE COUNTRY_CODE="1" VERIFY="1"><![CDATA[6194934998]]></MOBILEPHONE> </TOOLS> </CONTACTDATA> </TRUMPIA>

Is there any easy way to parse this since the field names are there?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top