XML ); foreach ($conf as $key => $value) { if ($key == "site") { $xml->addAttribute("site", $value); } else { $xmlGroup = $xml->addChild("group"); $xmlGroup->addAttribute("name", $key); foreach($value as $hostaddress => $servicesList) { $xmlHost = $xmlGroup->addChild("host"); $xmlHost->addAttribute("address", $hostaddress); if ($servicesList) foreach ($servicesList as $service) { $xmlService = $xmlHost->addChild("service"); $xmlService->addAttribute("name", $service); } } } } echo $xml->asXML(); ?>