How to transform xml tags to table columns in html?

0

XML:

<animal>
 <humano>
  <clientes>
   <cliente>
    <Nome_cli>Froslass</nome_cli>
    <Idade_cli>18</Idade_cli>
    <Ende_cli>Rua xyz</Ende_cli>
   </cliente>
   <cliente>
    <Nome_cli>Gengar</nome_cli>
    <Idade_cli>16</Idade_cli>
    <Ende_cli>Rua xyz</Ende_cli>
   </cliente>
  </clientes>
 </humano>
</animal>

HTML:

<html>
 <body>
  <table>
   <thead>
   <tr>
    <th>Nome do Cliente</th>
    <th>Idade</th>                       
    <th>Endereço</th>                        
   </tr>
   </thead>
   <tbody>                    
   <tr>                        
    <td>Froslass</td>                       
    <td>18</td>                       
    <td>Rua xyz</td>                        
   </tr>
   <tr>
    <td>Gengar</td>                        
    <td>16</td>                        
   <td>Rua xyz</td>
   </tr>
  </table>
 </body>
</html>

I wanted to leave it like this: link In short, I want to get straight from the xml, because if someone makes the change in the data order question, it would be updated directly, the only work I would have was to rename the patterns, type CI_Name for Client Name, etc.etc, AHHHH another thing, how do I go through the information directly, in case xml does not need to stay xml-> human-> clients-> client and go straight into xml-> client and grab all the information from these customers? What I think is to always get this information from the xml and with the help of php or javascript + DOM count which tags have inside the client tag create the columns, and get the value of each of these tags and fill the table: Client Name                                                                 Froslass                                                                 Gengar

    
asked by anonymous 02.04.2018 / 16:17

1 answer

1

About the issue

  

How do I go through the information directly, in case the xml does not   need to stay xml-> human-> clients-> client and go direct   in xml-> client and get all the information from these clients?

Using the DomDocument class of php (5,7) you can, follow an example

$file = new DomDocument();
$file->load("../myXmlFile.xml");
$clientes = $file->getElementsByTagName("clientes");

foreach($clientes as $cliente){
    echo $cliente->getAttribute("Nome_Cli");
}
    
02.04.2018 / 17:16