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