XMLReader - 没有错误的空白页

时间:2013-06-18 09:05:02

标签: php xml magento xmlreader magmi

我正在尝试将XML文件中的数据转换为数组,以便我可以通过'Magmi'导入它。使用以下代码,我正在使用3.6GB的XML文件。

<?php

$z = new XMLReader;
$z->open('wpcatsub.xml');

$doc = new DOMDocument;

// move to the first <App /> node
while ($z->read() && $z->name !== 'App');

// now that we're at the right depth, hop to the next <App/> until the end of the tree
while ($z->name === 'App')
{
    // either one should work
    //$node = new SimpleXMLElement($z->readOuterXML());
    $node = simplexml_import_dom($doc->importNode($z->expand(), true));

    // now you can use $node without going insane about parsing
    var_dump($node->element_1);

    // go to next <product />
    $z->next('App');
}

?>

当我加载PHP文件时,不会出现任何错误 - 页面只是空白。我的XML数据结构如下......

<App action="A" id="1">
    <BaseVehicle id= "17491"/>
    <Note><![CDATA[License Plate Lamp]]></Note>
    <Qty>.000</Qty>
    <PartType id= "10043"/>
    <Part>W0133-1620896</Part>
    <Product>
        <PartNumber>W0133-1620896</PartNumber>
        <BrandID>OES</BrandID>
        <BrandDescription><![CDATA[Genuine]]></BrandDescription>
        <WorldpacCategoryID>P9032</WorldpacCategoryID>
        <Price>29.85</Price>
        <ListPrice>33.17</ListPrice>
        <Available>Y</Available>
        <OEFlag>OEM</OEFlag>
        <Weight>.10</Weight>
        <Height>.7</Height>
        <Width>4.4</Width>
        <Length>4.4</Length>
        <SellingIncrement>1</SellingIncrement>
        <Popularity>D</Popularity>
        <ImageURL><![CDATA[http://img.eautopartscatalog.com/live/W01331620896OES.JPG]]></ImageURL>
        <ThumbURL><![CDATA[http://img.eautopartscatalog.com/live/thumb/W01331620896OES.JPG]]></ThumbURL>
    </Product>
    <ImageURL><![CDATA[http://img.eautopartscatalog.com/live/W01331620896OES.JPG]]></ImageURL>
    <ThumbURL><![CDATA[http://img.eautopartscatalog.com/live/thumb/W01331620896OES.JPG]]></ThumbURL>
</App>

由于文件的大小,它是否停滞?如果是这样,XMLReader是不是应该适用于大型XML文件?如果没有别的,我还有其他选择吗?

我想我可以根据需要将XML数据加载到数据库中,然后使用SELECT查询为MAGMI导入构建数组。虽然我不确定如何将XML文件导入SQL数据库。如果需要,我会很乐意得到指导。

0 个答案:

没有答案
相关问题