Esempio n. 1
0
 /**
  * The main function for converting to an XML document.
  * Pass in a multi dimensional array and this recrusively loops through and builds up an XML document.
  *
  * @static
  * @param  array $data
  * @param  string $rootNodeName - what you want the root node to be - defaultsto data.
  * @param  SimpleXMLElement $xml - should only be used recursively
  * @return string XML
  */
 public static function toXml($data, $rootNodeName = 'data', &$xml = NULL, $root_attributes = null)
 {
     if (is_null($xml)) {
         $xml = new SimpleXMLElement('<' . $rootNodeName . ' ' . $root_attributes . ' />');
     }
     // loop through the data passed in.
     foreach ($data as $key => $value) {
         // if numeric key, assume array of rootNodeName elements
         if (is_numeric($key)) {
             $key = $rootNodeName;
         }
         // Check if is attribute
         if ($key == TiendaArrayToXML::attr_arr_string) {
             // Add attributes to node
             foreach ($value as $attr_name => $attr_value) {
                 $xml->addAttribute($attr_name, $attr_value);
             }
         } else {
             // delete any char not allowed in XML element names
             $key = preg_replace('/[^a-z0-9\\-\\_\\.\\]/i', '', $key);
             // if there is another array found recrusively call this function
             if (is_array($value)) {
                 // create a new node unless this is an array of elements
                 $node = TiendaArrayToXML::isAssoc($value) ? $xml->addChild($key) : $xml;
                 // recrusive call - pass $key as the new rootNodeName
                 TiendaArrayToXML::toXml($value, $key, $node);
             } else {
                 // add single node.
                 $value = htmlentities($value);
                 $xml->addChild($key, $value);
             }
         }
     }
     // pass back as string. or simple xml object if you want!
     $dom = dom_import_simplexml($xml)->ownerDocument;
     $dom->formatOutput = true;
     return $dom->saveXML();
 }
Esempio n. 2
0
 /**
  * Generates the xml for the update request
  * @param unknown_type $product
  * @param string $etag - etag of the product
  */
 protected function getUpdateXML($product, $etag)
 {
     // perform the insertion
     Tienda::load('TiendaArrayToXML', 'library.xml');
     // Populate the xml request
     $xml = array();
     $xml['app:control']['sc:required_destination']['attributes']['dest'] = 'ProductSearch';
     // Title, id and description
     $xml['title'] = $product->product_name;
     $xml['content']['attributes']['type'] = 'text/html';
     $xml['content'] = $product->product_description;
     $xml['sc:id'] = $product->product_id;
     // Link to the product
     Tienda::load('TiendaHelperRoute', 'helpers.route');
     $xml['link']['attributes']['rel'] = 'alternate';
     $xml['link']['attributes']['type'] = 'text/html';
     $baseurl = str_replace("/administrator/", "/", JURI::base());
     $xml['link']['attributes']['href'] = $baseurl . TiendaHelperRoute::product($product->product_id);
     //$xml['link']['attributes']['href'] = 'http://www.weble.it/products/'.$product->product_id;
     // Condition
     $xml['scp:condition'] = 'new';
     // Price
     $currency_id = Tienda::getInstance()->get('default_currencyid', '1');
     Tienda::load('TiendaTableCurrencies', 'tables.currencies');
     $currency = JTable::getInstance('Currencies', 'TiendaTable');
     $currency->load((int) $currency_id);
     $xml['scp:price']['attributes']['unit'] = trim(strtoupper($currency->currency_code));
     $xml['scp:price']['@value'] = TiendaHelperBase::number(TiendaHelperProduct::getPrice($product->product_id)->product_price, array('num_decimals', '0'));
     // Manufacturer
     Tienda::load('TiendaTableManufacturers', 'tables.manufacturers');
     $manufacturer = JTable::getInstance('Manufacturers', 'TiendaTable');
     if ($manufacturer->load($product->manufacturer_id)) {
         $xml['scp:brand'] = $manufacturer->manufacturer_name;
     }
     $xml['entry']['attributes']['gd:etag'] = $etag;
     // Create the request
     $null = null;
     $helper = new TiendaArrayToXML();
     $ns = array(array('name' => 'app', 'url' => "http://www.w3.org/2007/app"), array('name' => 'gd', 'url' => "http://schemas.google.com/g/2005"), array('name' => 'sc', 'url' => "http://schemas.google.com/structuredcontent/2009"), array('name' => 'scp', 'url' => "http://schemas.google.com/structuredcontent/2009/products"));
     $xml = $helper->toXml($xml, 'entry', $null, $ns, "http://www.w3.org/2005/Atom");
     return $xml;
 }
Esempio n. 3
0
 function createRequest()
 {
     $arrayXml['AccessRequest']['UserId'] = $this->username;
     $arrayXml['AccessRequest']['Password'] = $this->password;
     $arrayXml['TrackingNumber'] = $this->track;
     $xml = trim(TiendaArrayToXML::toXml($arrayXml, 'DocumentRequest'));
     $this->request = $xml;
 }