dongling2038 2012-03-06 21:38
浏览 20
已采纳

来自此数组的null在哪里?

I am converting a php array into xml with something like this :

$bigArray = $readConnection->fetchAll($query);

  $doc = new DOMDocument();
  $doc->formatOutput = true;       
  $r = $doc->createElement( "DATA" );
  $doc->appendChild( $r );     
  foreach( $bigArray as $product )
  {
    $b = $doc->createElement( "ITEM" );        
    $product_type = $doc->createElement( "PRODUCT_TYPE" );
    $product_type->appendChild(
    $doc->createTextNode( $product['ProductType'] )
    );
    $b->appendChild( $product_type ); 
    $sku = $doc->createElement( "SKU" );
    $sku->appendChild(
    $doc->createTextNode( $product['SKU'] )
    );
    $b->appendChild( $sku ); 
    $r->appendChild( $b );
   }

  echo $doc->saveXML();

This returns an xml doc however at the very end null is being appended and I think that is what is causing me other problems. So for example at the bottom of the xml that is output it looks like :

  </ITEM>
</DATA>
null

This null value is coming from the original array I see if I do:

print_r($bigArray)

I see something like :

Array ( [0] => Array ( [ProductType] => simple [SKU] => 09423100010018 ) [1] => Array ( [ProductType] => simple [SKU] => 14552300010002 )) null

I am calling this from a class in magento like :

class Foo_Model_Queryone extends Mage_Core_Model_Abstract
{

    public function pprQuery() {
    $resource = Mage::getSingleton('core/resource');    
    $readConnection = $resource->getConnection('core_read');    
    $query = ("SELECT cpe.type_id AS 'ProductType',
      cpe.sku AS 'SKU',
      .....
  • 写回答

1条回答 默认 最新

  • duanchan5458 2012-03-07 00:50
    关注

    The Class Mage_Core_Model_Abstract is causing the problem, or another class higher up, that is outputting the null value.

    Try to step through it using Xdebug in Netbeans, and see what is causing the null value. I am interested to see the outcome.

    HTH

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?