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
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 "Marketing Name Market Rent ";
foreach($units as $unit) {
$marketingName = $xpath->evaluate("string(MITS:MarketingName)", $unit);
$marketRent = $xpath->evaluate("string(MITS:Information/MITS:MarketRent)", $unit);
echo "";
echo " " . $marketingName . " ";
echo " " . $marketRent . " ";
echo " ";
}
echo "
";
?>
Yields this output with MarketingName and MarketRent displayed together rather than separately per your request: