Creare un semplice file xml

spacca!  1 scarso!  0 versione stampa invia per email scheda utente totale visite  383
Vediamo alcuni metodi della classe php SimpleXMLElement, in particolare addChild() e asXML()
<?php

$xml = new SimpleXMLElement('<xml/>');
$info = $xml->addChild('info');
$info->addChild('update', date("Y-m-d H:m:s"));
for ($i = 1; $i <= 8; ++$i) {
    $video = $xml->addChild('video');
    $video->addChild('path', "video$i.avi");
    $video->addChild('title', "video $i - video Title");
}
$file = "file.xml";
$fr = fopen($file, 'w');
fwrite($fr, $xml->asXML());
fclose($fr);
Output generato
<?xml version="1.0"?>
<xml>
    <info>
        <update>2017-04-21 13:04:40</update>
    </info>
    <video>
        <path>video1.avi</path>
        <title>video 1 - video Title</title>
    </video>
    <video>
        <path>video2.avi</path>
        <title>video 2 - video Title</title>
    </video>
    <video>
        <path>video3.avi</path>
        <title>video 3 - video Title</title>
    </video>
    <video>
        <path>video4.avi</path>
        <title>video 4 - video Title</title>
    </video>
    <video>
        <path>video5.avi</path>
        <title>video 5 - video Title</title>
    </video>
    <video>
        <path>video6.avi</path>
        <title>video 6 - video Title</title>
    </video>
    <video>
        <path>video7.avi</path>
        <title>video 7 - video Title</title>
    </video>
    <video>
        <path>video8.avi</path>
        <title>video 8 - video Title</title>
    </video>
</xml>
 
 

Inserisci un commento

non sei loggato

CAPTCHA