예제 #1
0
 /**
  * Function builds OpenPayU Xml Document
  * @access public
  * @param string $data
  * @param string $rootElement
  * @param string $version
  * @param string $encoding
  * @param string $rootElementXsi
  * @return string $xml
  */
 public static function buildXmlFromArray($data, $rootElement, $version = '1.0', $encoding = 'UTF-8', $rootElementXsi = null)
 {
     if (!is_array($data)) {
         return null;
     }
     $xml = new XmlWriter();
     $xml->openMemory();
     $xml->setIndent(true);
     $xml->startDocument($version, $encoding);
     $xml->startElementNS(null, 'OpenPayU', 'http://www.openpayu.com/20/openpayu.xsd');
     $xml->startElement($rootElement);
     if (!empty($rootElementXsi)) {
         $xml->startAttributeNs('xsi', 'type', 'http://www.w3.org/2001/XMLSchema-instance');
         $xml->text($rootElementXsi);
         $xml->endAttribute();
     }
     self::convertArrayToXml($xml, $data);
     $xml->endElement();
     $xml->endElement();
     $xml->endDocument();
     return trim($xml->outputMemory(true));
 }