Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
XML
<?xml version="1.0" encoding="UTF-8" ?><table>
    <id title="161">            <name>sdffd</name>      <q>3232</q>     <price>323</price>  </id>
    <id title="162">            <name>sapana</name>     <q>12312</q>        <price>456123</price>   </id>
    <id title="163">            <name>sdsd</name>       <q>ewe</q>      <price>qwq</price>  </id>
    <id title="164">            <name>GDGFD</name>      <q>323</q>      <price>445</price>  </id>
    <id title="165">            <name>dsds</name>       <q>32323</q>        <price>2323</price> </id>
    <id title="166">            <name>ewewq</name>      <q>121</q>      <price>3232</price> </id>
</table>


i have this xml file i want to convet in html WITH THIS type look
Table
id 161 name sdffd q 3232 price 323
id 162 name sdffd q 12312 price 456123

i use this type code in php
XML
<?php

    include("config.php");
    $xml = simplexml_load_file("results.xml");
    echo $xml->getname()."<br/>";

    foreach($xml->children() as $child)
    {
    echo    $xml->body[0]->attributes();
    echo $child->getName() . ": " . $child . "<br />";
    }
?>


wich is show something like
table
id
id
id
id


pls tell me solution
Posted

1 solution

Try this as your foreach loop
PHP
<?php
// Your other code lines

echo "<table>";
foreach($xml->children() as $child)
{
        echo "<tr>";
            echo "<td>".$child->attributes()->title->getname()."</td>";
	    echo "<td>".$child->attributes()->title."</td>";
	    echo "<td>".$child->name->getname()."</td>";
	    echo "<td>".$child->name."</td>";
	    echo "<td>".$child->price->getname()."</td>";
	    echo "<td>".$child->price."</td>";		
	echo "</tr>";
}
echo "</table>";
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900