Set up XML from PHP

1

How I can extract the XML and add an ID so that it is in a format that is pleasing to the eye. Example:

<metadata>
    <data>Dato1</data>
    <data2>Dato2</data2>
    <data3>Dato3</data3>
<metadata>
    
asked by CometaRojo 23.01.2017 в 17:01
source

1 answer

1

You can use the tidy extension and send the result to the file.

<?php
$config = array(
           'indent'         => true,
           'wrap'           => 200,
           'output-xml' => true,
           'input-xml' => true
           );

$file = "/home/xxx/Documentos/prueba.xml";
$tidy = new tidy;
$tidy->parseString(file_get_contents($file), $config, 'utf8');
$tidy->cleanRepair();

echo $tidy;

you just have to write the file the previous code only prints it.

greetings

    
answered by 19.10.2017 в 19:27