Home > php_mysql > PHP XML traversing

PHP XML traversing

function parse_account_list($xml)
{
	$doc = new DOMDocument();
	$doc->loadXML($xml);
	$entries = $doc->getElementsByTagName('entry');
	$i = 0;
	$profiles = array();
	foreach($entries as $entry)
	{
		$profiles[$i] = array();

		$title = $entry->getElementsByTagName('title');
		$profiles[$i]["title"] = $title->item(0)->nodeValue;

		$entryid = $entry->getElementsByTagName('id');
		$profiles[$i]["entryid"] = $entryid->item(0)->nodeValue;

		$properties = $entry->getElementsByTagName('property');
		foreach($properties as $property)
		{
			if (strcmp($property->getAttribute('name'), 'ga:accountId') == 0)
				$profiles[$i]["accountId"] = $property->getAttribute('value');

			if (strcmp($property->getAttribute('name'), 'ga:accountName') == 0)
				$profiles[$i]["accountName"] = $property->getAttribute('value');

			if (strcmp($property->getAttribute('name'), 'ga:profileId') == 0)
				$profiles[$i]["profileId"] = $property->getAttribute('value');

			if (strcmp($property->getAttribute('name'), 'ga:webPropertyId') == 0)
				$profiles[$i]["webPropertyId"] = $property->getAttribute('value');
		}

		$tableId = $entry->getElementsByTagName('tableId');
		$profiles[$i]["tableId"] = $tableId->item(0)->nodeValue;

		$i++;
	}
	return $profiles;
}
Categories: php_mysql Tags:
  1. No comments yet.
  1. No trackbacks yet.

17043 pages viewed, 0 today
11075 visits, 0 today
FireStats icon Powered by FireStats