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"?>
<Answer>
<APITimestamp>2010-12-14T19:07:39.000</APITimestamp>
<Products>
<Product toBeDiscontinued="N" discontinueDate="" estDeliveryDate="">
<ProductCode><![CDATA[00-238X1]]></ProductCode>
<InventoryLevel>69</InventoryLevel>
</Product>
.
.
.

I’m connecting via soap as shown below:

<?php

//include the Magento API file - replace with your server path to the file
require_once('app/Mage.php');

// ***** Configuration ******
//$myDomain = 'http://mydomain.com.com/api?wsdl';
$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?

Ron

Woooohoooo…figured it out!

Last line should have been:

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