PHP Classes

File: reading.php

Recommend this page to a friend!
  Classes of Diego Feitosa   DOM Adapter   reading.php   Download  
File: reading.php
Role: Example script
Content type: text/plain
Description: Reading example
Class: DOM Adapter
Access XML documents with DOM API in PHP 4 and 5
Author: By
Last change:
Date: 17 years ago
Size: 901 bytes
 

Contents

Class file image Download
<?php
/*
 * This is a simple example to show the reading process of a xml document.
 * This example works with PHP4 and PHP5.
 *
 * This model was extracted from the PHP Manual at 'DOM Functions'
 * chapter
*/
require_once("DOMAdapter.inc");
header("Content-Type: text/plain");

$xml = new DOMAdapter();

$doc = $xml->createDocument();
$doc->load("movies.xml");

$nodes = $doc->documentElement->childNodes;

echo
"=== Movies ===\n\n";

for (
$i = 0; $i < $nodes->length; $i++) {
   
$node = $nodes->item($i);
    if (
$node->nodeType != XML_ELEMENT_NODE)
        continue;

   
$movie = $node->childNodes;

    echo
"Release Year: ".$node->getAttribute("year")."\n";
    for (
$j = 0; $j < $movie->length; $j++) {
       
$data = $movie->item($j);
        if (
$data->nodeType != XML_ELEMENT_NODE)
            continue;

        echo
ucfirst($data->nodeName) .": ".$data->nodeValue."\n";
    }

    echo
"\n\n";
}
?>