Dealing with poor XML (or maybe just poor XML skills)

I have the following XML file I’m trying to use to update my inventory automatically.

<?xml version="1.0" encoding="UTF-8"?>
<Product toBeDiscontinued="N" discontinueDate="" estDeliveryDate="">

I’m connecting via soap as shown below:


//include the Magento API file - replace with your server path to the file

// ***** Configuration ******
//$myDomain = '';
$myAPILogin = 'login';
$myAPIKey = 'apikey';
// get my saved file name
$myFilename = 'trademark_commerce.xml'; //this file does exist on my server

//load up local xml file for processing
$feed_xml = simplexml_load_file($myFilename);

// Begin SOAP Requests
$client = new SoapClient($myDomain.'/api/?wsdl');
$session = $client->login($myAPILogin, $myAPIKey);
$updatedProducts = "";
//some counters - counting loops this way lets me see and set where the count increments
$x = 0;
//some filter date to pass to the API - add more to filter your results further - see Magento API docs
$filterData = array('type'=>'simple');
//get all my database products into an array
$products = $client->call($session, 'catalog_product.list', array($filterData));

//loop through my product array
echo "Starting product loop...<br/><br/>";
foreach ($products as $product) {
//get my database product sku - for cleaner reference in the code
$mysku = $product['sku'];

//search directly in the product sku attribute in the xml for my sku
$res = $feed_xml->xpath("//Product[@ProductCode='$mysku']");

Something isn’t working with the last line. It just won’t find the ProductCode to match with the sku in the database.

Any ideas what I could be doing wrong?


Woooohoooo…figured it out!

Last line should have been:

$res = $feed_xml->xpath("//Product[ProductCode='$mysku']");