protected function RestfulFormatterHalXml::arrayToXML in RESTful 7
Converts the input array into an XML formatted string.
Parameters
array $data: The input array.
SimpleXMLElement $xml: The object that will perform the conversion.
Return value
SimpleXMLElement
File
- modules/
restful_example/ plugins/ formatter/ RestfulFormatterHalXml.class.php, line 34 - Contains RestfulFormatterHalJson.
Class
- RestfulFormatterHalXml
- @file Contains RestfulFormatterHalJson.
Code
protected function arrayToXML(array $data, SimpleXMLElement $xml) {
foreach ($data as $key => $value) {
if (is_array($value)) {
if (!is_numeric($key)) {
$subnode = $xml
->addChild("{$key}");
$this
->arrayToXML($value, $subnode);
}
else {
$subnode = $xml
->addChild("item{$key}");
$this
->arrayToXML($value, $subnode);
}
}
else {
$xml
->addChild("{$key}", htmlspecialchars("{$value}"));
}
}
return $xml;
}