Hello forums,
I have a curl function that posts data to a receiving script and the script is returning an xml document:
<?xml version=“1.0” encoding=“UTF-8”?>
<?xml-stylesheet type=“text/xsl” href=“genericPostlead_xsl.php”?>
<response>
<status>Unmatched</status>
<lead_id>93189</lead_id>
</response >
Question ?
How can I get the first child of this xml w/ is “Unmatched”. Haven’t worked with domDocument before any ideas?
Thanks
Maybe this sample can help you.
<?php
$doc = new DOMDocument;
$doc->load('book.xml');
$items = $doc->getElementsByTagName('entry');
for ($i = 0; $i < $items->length; $i++) {
echo $items->item($i)->nodeValue . "\
";
}
?>
Thanks thietkeweb But it gives an error:
Fatal error: Call to a member function getElementsByTagName() on a non-object in C:\wamp\www\s\curl.php
$var='https://leads.callconnectleads.com/genericPostlead.php?Test_Lead=1&TYPE=7&IP_Address=75.2.92.149&SRC=test&Landing_Page=landing&Sub_ID=12&Pub_ID=12345&First_Name=John&Last_Name=Doe&Address=123%20Main%20St.&City=Chicago&State=IL&Zip=60610&Email=test@nags.us&Home_Phone=3125556491&Cell_Phone=3125559682&Best_Time_To_Contact=Morning&Home_Improvement_Product=Bathroom%20Remodel&Prospect_Owns_Property=Yes&Need_Financing=Yes&Comments=Comments';
$request = curl_init($var);
curl_setopt($request, CURLOPT_HEADER, 0);
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE);
$post_response = curl_exec($request);
curl_close ($request);
$doc = new DOMDocument;
$items = $post_response->getElementsByTagName('status');
for ($i = 0; $i < $items->length; $i++) {
echo $items->item($i)->nodeValue . "\
";
}
$post_response is holding the xml (try echo $post_response);
Do you have any idea why? getElementsByTagName() exists on the DomDocument class.
Thanks
Try this:
<?php
$var='https://leads.callconnectleads.com/genericPostlead.php?Test_Lead=1&TYPE=7&IP_Address=75.2.92.149&SRC=test&Landing_Page=landing&Sub_ID=12&Pub_ID=12345&First_Name=John&Last_Name=Doe&Address=123%20Main%20St.&City=Chicago&State=IL&Zip=60610&Email=test@nags.us&Home_Phone=3125556491&Cell_Phone=3125559682&Best_Time_To_Contact=Morning&Home_Improvement_Product=Bathroom%20Remodel&Prospect_Owns_Property=Yes&Need_Financing=Yes&Comments=Comments';
$request = curl_init($var);
curl_setopt($request, CURLOPT_HEADER, 0);
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE);
$post_response = curl_exec($request);
curl_close ($request);
$doc = new DOMDocument;
$doc->loadXML($post_response);
$items = $doc->getElementsByTagName('status');
for ($i = 0; $i < $items->length; $i++) {
echo $items->item($i)->nodeValue . "\
";
}
?>
Your code was wrong because $post_response is not a DOMDocument object, so it didn’t have the method getElementsByTagName().
Gee thanks it’s working now I should have loaded the response first with
$doc->loadXML($post_response);
Thanks you rule!!
You’re welcome! I’m new to this forum. 
Thanks for being here noob guys like me badly needs you here 