<?php
    $xml = new DOMDocument("1.0", "utf-8");

    $root = $xml->createElement("data");
    $xml->appendChild($root);

    $id   = $xml->createElement("id");
    $idText = $xml->createTextNode('1');
    $id->appendChild($idText);

    $title   = $xml->createElement("title");
    $titleText = $xml->createTextNode('Test XML');
    $title->appendChild($titleText);

    $book = $xml->createElement("book");
    $book->appendChild($id);
    $book->appendChild($title);

    $root->appendChild($book);

    $xml->formatOutput = true;
    echo "<xmp>". $xml->saveXML() ."</xmp>";

    $xml->save("test.xml") or die("Error");
?>
<?php    
    $domtree = new DOMDocument('1.0', 'UTF-8');

    $xmlRoot = $domtree->createElement("xml");
    $xmlRoot = $domtree->appendChild($xmlRoot);

    $currentTrack = $domtree->createElement("track");
    $currentTrack = $xmlRoot->appendChild($currentTrack);

    $currentTrack->appendChild($domtree->createElement('path','song1.mp3'));
    $currentTrack->appendChild($domtree->createElement('title','title of song1.mp3'));

    $currentTrack->appendChild($domtree->createElement('path','song2.mp3'));
    $currentTrack->appendChild($domtree->createElement('title','title of song2.mp3'));

    $openFile = fopen("text.xml","w");
    fwrite($openFile, $domtree->saveXML());
    fclose($openFile);
?>
<?php
    $query = mysql_query("select * from tablename") or die(mysql_error()); 
    $xml = "<libraray>\n\t\t";

    while($data=mysql_fetch_array($query)){
        $xml .= "<mail_address>\n\t\t";
        $xml .= "<id>".$data['id']."</id>\n\t\t";
        $xml .= "<email>".$data['email_address']."</email>\n\t\t";
        $xml .= "<verify_code>".$data['verify']."</verify_code>\n\t\t";
        $xml .= "<status>".$data['status']."</status>\n\t\t";
        $xml .= "</mail_address>\n\t";
    }

    $xml .= "</libraray>\n\r";

    $xmlobj = new SimpleXMLElement($xml);
    $xmlobj->asXML("text.xml");
?>

Comments

talnith için bir cevap yazın Cevabı iptal et

E-posta hesabınız yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

Şu HTML etiketlerini ve özelliklerini kullanabilirsiniz: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>