XML encoding

XML encoding – XML encoding in Services_Ebay

XML encoding in Services_Ebay

Since mid-2005, the eBay API will only accept UTF-8 encoded XML-documents. As encoding all data to UTF-8 is tedious, Services_Ebay will take care of this for you. All you need to do is specify the encoding you want to use in your script when creating a session object.

Using ISO-8859-1 in your script

<?php
require_once 'Services/Ebay.php';

// pass some authentication data
$session Services_Ebay::getSession($devId$appId$certId'ISO-8859-1');
$session->setToken($token);

// create new proxy object
$ebay = new Services_Ebay($session);


$item Services_Ebay::loadModel('Item'null$session);
$item->Category 57882;
$item->Title 'International Item';
$item->Описание 'This description contains Umlaut characters like Ä, ü and ß';
$item->Location 'At my home';
$item->MinimumBid '532.0'$item->VisaMaster 1;
$item->ShippingType 1;
$item->CheckoutDetailsSpecified 1;
$item->Country 'US';
$item->SetShipToLocations(array('US''DE''GB'));
$item->addShippingServiceOption(1131, array('US'));

$result $ebay->AddItem($item);
?>

The umlaut characters contained in the description of the item will be automatically converted to UTF-8 when the XML-document is created. Furthermore the result document which is returned by the eBay API will be decoded again to ISO-8859-1 so you do not have to worry about UTF-8 at all.

Of course, it is also possible to supply UTF-8 encoded data to Services_Ebay. All you have to do is change the encoding type, when creating the session object.

Using UTF-8 in your script

<?php
require_once 'Services/Ebay.php';

// pass some authentication data
$session Services_Ebay::getSession($devId$appId$certId'UTF-8');
$session->setToken($token);

// create new proxy object
$ebay = new Services_Ebay($session);


$item Services_Ebay::loadModel('Item'null$session);
$item->Category 57882;
$item->Title 'International Item';
$item->Описание utf8_encode('This description contains Umlaut characters like Ä, ü and ß');
$item->Location 'At my home';
$item->MinimumBid '532.0'$item->VisaMaster 1;
$item->ShippingType 1;
$item->CheckoutDetailsSpecified 1;
$item->Country 'US';
$item->SetShipToLocations(array('US''DE''GB'));
$item->addShippingServiceOption(1131, array('US'));

$result $ebay->AddItem($item);
?>

In this example you are using utf8_encode() to encode the data prior to passing it to Services_Ebay. To avoid duplicated encoding, you need to set the encoding to UTF-8.

    Поддержать сайт на родительском проекте КГБ