Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $dom = new DomDocument();
- $dom->load("cars.xml");
- echo '<table>';
- echo '<tr>
- <td>BRAND</td>
- <td>MODEL</td>
- <td>COLOR</td>
- <td>YEAR</td>
- <td>PRICE</td>
- </tr>';
- foreach ($dom->documentElement->childNodes as $element) {
- if($element->nodeName == "car"){
- echo "<tr>";
- foreach ($element->childNodes as $car) {
- if ($car->nodeType == 1 && $car->nodeName == "brand"){
- echo '<td>'.$car->textContent."</td>";
- }
- if ($car->nodeType == 1 && $car->nodeName == "model"){
- echo '<td>'.$car->textContent."</td>";
- }
- if ($car->nodeType == 1 && $car->nodeName == "color"){
- echo '<td>'.$car->textContent."</td>";
- }
- if ($car->nodeType == 1 && $car->nodeName == "year"){
- echo '<td>'.$car->textContent."</td>";
- }
- if ($car->nodeType == 1 && $car->nodeName == "price"){
- echo '<td>'.$car->textContent."</td>";
- }
- }
- echo "</tr>";
- }
- }
- echo "<table>";
- echo "all is good<br/>";
Advertisement
Add Comment
Please, Sign In to add comment