douxuanling6523 2012-08-30 05:03
浏览 23
已采纳

使用PHP在非常大的XML FEED中搜索数据

http://www.topbuy.com.au/tbcart/tbadmin/datafeed/shoppingcom.xml

This is my feed url which never opens in browser or takes hours to open it.

I want to create PHP page where i want to put a searchbox ( where i will put ) in my PHP page and once hit submit my PHP code should search and display corresponding products PRICE.

So shall i use SimpleXML for this or any other recommendations ?

<Products>
<Product><MPN><![CDATA[INK-PE-009]]></MPN><Manufacturer><![CDATA[Epson]]></Manufacturer><ProductName><![CDATA[Epson T009 Colour Compatible Inkjet Cartridge]]></ProductName><ProductURL><![CDATA[http://www.topbuy.com.au/tbcart/pc/Epson-T009-Colour-Compatible-Inkjet-Cartridge-p3343.htm?utm_source=TopBuy_ShoppingCom&utm_content=&utm_medium=cpc&dismode=1&utm_campaign=TBDF-XX10421]]></ProductURL><ProductType><![CDATA[Compatible Ink Cartridges]]></ProductType><ImageURL><![CDATA[http://www2.topbuy.com.au/tbcart/pc/catalog/General/TBDF-XX10421_1.jpg]]></ImageURL><Price>4.09</Price><OriginalPrice>9</OriginalPrice><Category><![CDATA[Consumables->Compatible Ink Cartridges]]></Category><ProductDescription><![CDATA[$4.05 Cash Price see store for detailsRelated Brand  EpsonOriginal Cartridge Equivalent T009Related Printers STYLUS 1270, STYLUS 1280, STYLUS 1290, STYLUS 3300C, STYLUS PHOTO 1270, STYLUS PHOTO 1290, STYLUS PHOTO 1290 silverThis cartridge works in the following printers  Epson Stylus Photo 1270/1280Please check the name (code) of the cartridge in your printer before ordering to ensure that it matches the name of the cartridges you are ordering from us. In some instances a printer can take more than one cartridge type and ...]]></ProductDescription><Stock>Y</Stock><ShippingCost>10</ShippingCost><StockDescription>No.1 OZ SUPERSTORE AUS WARRANTY FAST SHIPPING</StockDescription><Condition>Brand New</Condition></Product>
<Product><MPN><![CDATA[INK-PE-013]]></MPN><Manufacturer><![CDATA[Epson]]></Manufacturer><ProductName><![CDATA[Epson T013 Black Compatible Inkjet Cartridge]]></ProductName><ProductURL><![CDATA[http://www.topbuy.com.au/tbcart/pc/Epson-T013-Black-Compatible-Inkjet-Cartridge-p3345.htm?utm_source=TopBuy_ShoppingCom&utm_content=&utm_medium=cpc&dismode=1&utm_campaign=TBDF-XX10423]]></ProductURL><ProductType><![CDATA[Compatible Ink Cartridges]]></ProductType><ImageURL><![CDATA[http://www2.topbuy.com.au/tbcart/pc/catalog/General/TBDF-XX10423_1.jpg]]></ImageURL><Price>2.09</Price><OriginalPrice>5</OriginalPrice><Category><![CDATA[Consumables->Compatible Ink Cartridges]]></Category><ProductDescription><![CDATA[$2.07 Cash Price see store for detailsRelated Brand  EpsonOriginal Cartridge Equivalent T013Related Printers STYLUS COLOR 480, STYLUS COLOR 580, STYLUS COLOR C20, STYLUS COLOR C40, STYLUS COLOUR 480, STYLUS COLOUR 580, STYLUS COLOUR C20UX, STYLUS COLOUR C40SX, STYLUS COLOUR C40UXThis cartridge works in the following printers  Epson Stylus Colour 480/580Please check the name (code) of the cartridge in your printer before ordering to ensure that it matches the name of the cartridges you are ordering from us. In some instances a ...]]></ProductDescription><Stock>Y</Stock><ShippingCost>10</ShippingCost><StockDescription>No.1 OZ SUPERSTORE AUS WARRANTY FAST SHIPPING</StockDescription><Condition>Brand New</Condition></Product>
  • 写回答

1条回答 默认 最新

  • dsplos5731 2012-08-30 07:05
    关注

    I would recommend to use the XMLReader class because it doesn't require to load the full xml into memory at once.

    The downside is that you will have to implement searching and filtering by hand, for a simple name searching you can do something like this:

    $reader = new XMLReader;
    $reader->open('shoppingcom.xml');
    
    while ($reader->read()) {
        if ($reader->name == 'Product') {
            $productxml = $reader->readOuterXML();
            while ($reader->read()) {
                if ($reader->name == 'ProductName' && stristr($reader->readInnerXML(), 'adidas')) {
                    print $productxml;
                    // now it contains the <Product>...</Product> fragment of the xml
                    // you can use simplexml on this fragment, or just add an if for Prize node
                }
                if ($reader->name == 'Product' && $reader->nodeType == XMLReader::END_ELEMENT) {
                    break;
                }
            }
        }
    }
    

    Still, the example feed is solid 64M, you might have better results for live searching if you create a database for this that could index the fields you want to search for and returns the xml fragments, so you don't have to normalize everything to tables.

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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题