Combining two Xpaths into one loop?

前端 未结 3 439
故里飘歌
故里飘歌 2021-01-22 17:03

I\'m using xpath to grab information from a document, the only issue is I havn\'t been able to combine them into 1 for loop so the information displays correctly on the page. My

3条回答
  •  执念已碎
    2021-01-22 17:15

    I couldn't resist to give this another try to apply a model on some XML source. I opted for SimpleXMLElement for this answer. It is merely transparent and has mostly only implications on the xpath expressions. It should be possible to translate the same interface to DOMDocument.

    $unitPrototype = new XPrototype(
        "//ILS_Unit[@FloorplanID='550584']/Unit",
        [
            'name'  => 'MITS:MarketingName',
            'price' => 'MITS:Information/MITS:MarketRent'
        ]
    );
    
    $units = new XList('http://mdoerrdev.com/xml/updates-mits.xml', $unitPrototype);
    
    foreach ($units as $unit) {
        echo
        $unit->name, " ",
        $unit->price, "\n";
    }
    

    The source of the used types like XPrototype and XList is on Github: XObjects.php.

提交回复
热议问题