Coding Cheatsheets - Learn web development code and tutorials for Software developers which will helps you in project. Get help on JavaScript, PHP, XML, and more.

Post Page Advertisement [Top]


    <song dateplayed="2011-07-24 19:40:26">
        <title>I left my heart on Europa</title>
        <artist>Ship of Nomads</artist>
    <song dateplayed="2011-07-24 19:27:42">
        <title>Oh Ganymede</title>
    <song dateplayed="2011-07-24 19:23:50">
        <artist>Jewitt K. Sheppard</artist>

    $mysongs = simplexml_load_file('songs.xml');
    echo "<ul id="songlist">n";
    foreach ($mysongs as $songinfo):
        echo "<li><div class="title">",$title,"</div><div class="artist">by ",$artist,"</div><time>",$date,"</time></li>n";
    echo "</ul>";


$xmlData =<<< END

<?xml version="1.0"?>





      <title>PHP XML EXAMPLES</title>    

      <author>SUDHIR PANDEY</author>





$xml = simplexml_load_string($xmlData)

       or die("Error: Can not create object");


simplexml_load_string() : Interprets a string of XML into an object

$xml = simplexml_load_file("books.xml")
       or die("Error: Cannot create object");
foreach($xml->children() as $books){

    foreach($books->children() as $book => $data){

      echo $data->id;

      echo $data->title;

      echo $data->author;

      echo "<br />";



children() — Finds children of given node
$xml = simplexml_load_file("books.xml")
       or die("Error: Cannot create object");
function processXML($node){

  foreach($node->children() as $books => $data){

    if(trim($data) != ""){

      echo $books.": ".$data;

      echo "<br />";







Create XML
$xml = new DOMDocument("1.0");
$root = $xml->createElement("data");
$id   = $xml->createElement("id");
$idText = $xml->createTextNode('1');
$title   = $xml->createElement("title");
$titleText = $xml->createTextNode('"PHP Undercover"');
$book = $xml->createElement("book");
$xml->formatOutput = true;
echo "<xmp>". $xml->saveXML() ."</xmp>";
$xml->save("mybooks.xml") or die("Error");

No comments:

Post a Comment

Bottom Ad [Post Page]