vladislavkopilov

11-2

Nov 21st, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. $dom = new DomDocument();
  2.     $dom->load("cars.xml");
  3.     echo '<table>';
  4.     echo '<tr>
  5.             <td>BRAND</td>
  6.             <td>MODEL</td>
  7.             <td>COLOR</td>
  8.             <td>YEAR</td>
  9.             <td>PRICE</td>
  10.         </tr>';
  11.     foreach ($dom->documentElement->childNodes as $element) {
  12.         if($element->nodeName == "car"){
  13.             echo "<tr>";
  14.             foreach ($element->childNodes as $car) {
  15.                 if ($car->nodeType == 1 && $car->nodeName == "brand"){
  16.                     echo '<td>'.$car->textContent."</td>";
  17.                 }
  18.                 if ($car->nodeType == 1 && $car->nodeName == "model"){
  19.                     echo '<td>'.$car->textContent."</td>";
  20.                 }
  21.                 if ($car->nodeType == 1 && $car->nodeName == "color"){
  22.                     echo '<td>'.$car->textContent."</td>";
  23.                 }
  24.                 if ($car->nodeType == 1 && $car->nodeName == "year"){
  25.                     echo '<td>'.$car->textContent."</td>"; 
  26.                 }
  27.                 if ($car->nodeType == 1 && $car->nodeName == "price"){
  28.                     echo '<td>'.$car->textContent."</td>"; 
  29.                 }
  30.             }
  31.             echo "</tr>";
  32.         }
  33.     }
  34.     echo "<table>";
  35.     echo "all is good<br/>";
Advertisement
Add Comment
Please, Sign In to add comment