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

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

报告相同问题?

悬赏问题

  • ¥15 Pyqt 如何正确的关掉Qthread,并且释放其中的锁?
  • ¥30 网站服务器通过node.js部署了一个项目!前端访问失败
  • ¥15 WPS访问权限不足怎么解决
  • ¥15 java幂等控制问题
  • ¥15 海湾GST-DJ-N500
  • ¥15 氧化掩蔽层与注入条件关系
  • ¥15 Django DRF 如何反序列化得到Python对象类型数据
  • ¥15 多数据源与Hystrix的冲突
  • ¥15 如何在线硕士了解,广告太多,希望有真实接触过的人回答下?(标签-学习|关键词-在线硕士)
  • ¥15 zabbix6.4与frp如何进行联动