Combining two Xpaths into one loop?

前端 未结 3 435
故里飘歌
故里飘歌 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:12

    Use the context node argument of $xpath->evaluate()...

    Your code with these adjustments:

    preserveWhiteSpace = false;
    $doc->load('http://mdoerrdev.com/xml/updates-mits.xml');
    
    $xpath = new DOMXPath($doc);
    $xpath->registerNamespace('MITS', "http://www.mitsproject.org/namespace");
    
    $units = $xpath->evaluate("//ILS_Unit[@FloorplanID='550584']/Unit");
    echo "";
    echo "";
    foreach($units as $unit)  {
      $marketingName = $xpath->evaluate("string(MITS:MarketingName)", $unit);
      $marketRent = $xpath->evaluate("string(MITS:Information/MITS:MarketRent)", $unit);
      echo "";
      echo "  ";
      echo "  ";
      echo "";
    }
    echo "
    Marketing NameMarket Rent
    " . $marketingName . "" . $marketRent . "
    "; ?>

    Yields this output with MarketingName and MarketRent displayed together rather than separately per your request:

    enter image description here

提交回复
热议问题