我轉換一個PHP數組轉換成XML像這樣的東西:null在這個數組中是從哪裏來的?
$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();
這將返回在最後空被追加然而一個XML文檔,我認爲這是什麼原因造成了我其他的問題。因此,例如在XML的底部,也就是它看起來像輸出:
</ITEM>
</DATA>
null
此空值從原來的陣列我看得出來,如果我做的:
print_r($bigArray)
我看到的是這樣的:
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',
.....
:
Array ([0] => Array ([ProductType] => simple [SKU] => 09423100010018) [1] => Array ([ProductType] => simple [SKU] => 14552300010002)) null
我從一類在Magento像調用此
腳本是否在'echo $ doc-> saveXML();'之後結束?我從來沒有''saveXML()'隨機通過'空'出...尤其是沒有其他錯誤 – 2012-03-06 21:42:25
是的,那是腳本的結束。我正在從Magento模型中的一個類中運行這個..也許這就是爲什麼它很時髦 – Zac 2012-03-06 21:45:41
我認爲這個'null'更可能是由繼承層次結構中更高的另一個類輸出的,即從測試/調試代碼在你正在擴展的課程中。 – 2012-03-06 22:06:26