Home > php_mysql > PHP XML traversing

PHP XML traversing

PHP:
  1. function parse_account_list($xml)
  2. {
  3.     $doc = new DOMDocument();
  4.     $doc->loadXML($xml);
  5.     $entries = $doc->getElementsByTagName('entry');
  6.     $i = 0;
  7.     $profiles = array();
  8.     foreach($entries as $entry)
  9.     {
  10.         $profiles[$i] = array();
  11.  
  12.         $title = $entry->getElementsByTagName('title');
  13.         $profiles[$i]["title"] = $title->item(0)->nodeValue;
  14.  
  15.         $entryid = $entry->getElementsByTagName('id');
  16.         $profiles[$i]["entryid"] = $entryid->item(0)->nodeValue;
  17.  
  18.         $properties = $entry->getElementsByTagName('property');
  19.         foreach($properties as $property)
  20.         {
  21.             if (strcmp($property->getAttribute('name'), 'ga:accountId') == 0)
  22.                 $profiles[$i]["accountId"] = $property->getAttribute('value');
  23.  
  24.             if (strcmp($property->getAttribute('name'), 'ga:accountName') == 0)
  25.                 $profiles[$i]["accountName"] = $property->getAttribute('value');
  26.  
  27.             if (strcmp($property->getAttribute('name'), 'ga:profileId') == 0)
  28.                 $profiles[$i]["profileId"] = $property->getAttribute('value');
  29.  
  30.             if (strcmp($property->getAttribute('name'), 'ga:webPropertyId') == 0)
  31.                 $profiles[$i]["webPropertyId"] = $property->getAttribute('value');
  32.         }
  33.  
  34.         $tableId = $entry->getElementsByTagName('tableId');
  35.         $profiles[$i]["tableId"] = $tableId->item(0)->nodeValue;
  36.  
  37.         $i++;
  38.     }
  39.     return $profiles;
  40. }

Categories: php_mysql Tags:
  1. No comments yet.
  1. No trackbacks yet.
94310 pages viewed, 370 today
49928 visits, 74 today
FireStats icon Powered by FireStats