You are here

public static function Braintree_Xml_Generator::arrayToXml in Commerce Braintree 7

arrays passed to this method should have a single root element with an array as its value

Parameters

array $aData the array of data:

Return value

var XML string

1 call to Braintree_Xml_Generator::arrayToXml()
Braintree_Xml::buildXmlFromArray in braintree_php/lib/Braintree/Xml.php

File

braintree_php/lib/Braintree/Xml/Generator.php, line 22

Class

Braintree_Xml_Generator
Generates XML output from arrays using PHP's built-in XMLWriter

Code

public static function arrayToXml($aData) {

  // set up the XMLWriter
  $writer = new XMLWriter();
  $writer
    ->openMemory();
  $writer
    ->setIndent(true);
  $writer
    ->setIndentString(' ');
  $writer
    ->startDocument('1.0', 'UTF-8');

  // get the root element name
  $aKeys = array_keys($aData);
  $rootElementName = $aKeys[0];

  // open the root element
  $writer
    ->startElement(Braintree_Util::camelCaseToDelimiter($rootElementName));

  // create the body
  self::_createElementsFromArray($writer, $aData[$rootElementName], $rootElementName);

  // close the root element and document
  $writer
    ->endElement();
  $writer
    ->endDocument();

  // send the output as string
  return $writer
    ->outputMemory();
}