Jump to content

Recommended Posts

hi, I'm trying to parse an xml string in the following format

 


$response = "
<system>
  <status>success</status>
  <resultlist>
    <resultlist id='1'>
      <result id='{field_name}'>{field_value}</result>
      ...
    </resultlist>
    <resultlist id='2'>
      <result id='{field_name}'>{field_value}</result>
      ...
    </resultlist>
    ...
  </resultlist>
</system>";

 

I've tried running

$xml[] = simplexml_load_string($response); //each resulting xml

 

foreach($xml as $entry)
	{
		$result[] = $entry->resultlist->result[4];
	}

 

The result array returns NULL.

 

Link to comment
https://forums.phpfreaks.com/topic/172699-solved-simplexml_load_string/
Share on other sites

  • 3 weeks later...

ok,  I'm no longer storing it within an array since it wasn't necessary.

 

retrieves the return xml string

public function list_users($config)
{
$login = $config->get_username();
$password = $config->get_password();
$listid = $config->get_listid();

$request = "<system>".
  "<action>getsubscribers</action>".
  "<authorization>".
    "<username>".$login."</username>".
    "<password>".$password."</password>".
  "</authorization>".
  "<parameterlist>".
"<parameter id='List ID'><value>".$listid."</value></parameter>".
"<parameter id='Search Relation'><value>and</value></parameter>".
    "<parameterarr>".
    "</parameterarr>".
  "</parameterlist>".
"</system>";


return $this->_xml = $request;
}

public function query($entry)
{
		// Configuration
		$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
		$url = "http://server1.streamsend.com/streamsend/api.php";

		// Build Parameters
		$params['xmldata'] = $entry;

		// Open Connection Handle
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_POST,1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

		curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
		// Send Request
		$response = curl_exec ($ch);

		// Close Connection Handle
		curl_close ($ch);

		$xml = simplexml_load_string($response);





	return $this->_result = $xml;
}

 

bit of code which should be parsing the xml string

//$list == the resulting xml from the above code

foreach($list->resultlist as $item)
{
echo '<pre>';
echo var_dump($item);
echo '</pre>';

}


This returns every user who met the search criteria

How would I reference each one of them uniquely though? 

 

You'll see from reading the streamsend API documentation that the string will return a number of <result> tags; each one made unique by an "id" property value. 

 

foreach($list->resultlist->result as $item) still returns a blank page.  Maybe I need to reference each of the result tags based on property value? 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.