PHP Classes

File: xmlparsertest.php

Recommend this page to a friend!
  Classes of Saravanan   xmlparser   xmlparsertest.php   Download  
File: xmlparsertest.php
Role: Sample output
Content type: text/plain
Description: Example file which describes how to use the ezxml parser
Class: xmlparser
This is a modified version of EZXML parser
Author: By
Last change: I have given the location where the source for class can be downloaded
Date: 22 years ago
Size: 3,316 bytes
 

Contents

Class file image Download
<? //please note before running this file please download the XMLparser //from http://www.shipstaff.com/XMLPARSER.zip //without this notjhing is going to work include("XMLPARSER/ezxml.php"); $xmlDocument = "<?xml version=\"1.0\"?> <document version=\"42\"> <person> <firstname value=\"Bård\" /> <lastname value=\"Farstad\" /> <description> Coder. </description> </person> <person> <firstname value=\"Christoffer A.\" /> <lastname value=\"Elo\" /> <description> Coder. </description> </person> </document>"; $tree =eZXML::domTree($xmlDocument, array( "TrimWhiteSpace" => true )); foreach ($tree->children as $document) { // parse the document if ( $document->name == "document" ) { // get the document version attribute foreach ($document->attributes as $documentAttr) { if ( $documentAttr->name == "version" ) { print( "Found document with version: " . $documentAttr->content . "<br>" ); } } // parse all persons foreach ( $document->children as $person ) { if ( $person->name == "person" ) { print( "Found a new person <br>" ); $firstName = ""; $lastName = ""; $descriptionName = ""; // get the name and description foreach ( $person->children as $personAttribute ) { //echo $personAttribute->name; //echo '<br>'; switch ( $personAttribute->name ) { case "firstname" : { //$firstName = $firstname->content; $firstName = getAttrValue( $personAttribute, "value" );; }break; case "lastname" : { $lastName = getAttrValue( $personAttribute, "value" ); }break; case "description" : { //this is the only modification from previous version $description=get_contents($personAttribute); // get the description text /* foreach ( $personAttribute->children as $description21 ) { $description = $description21->content; */ /* if ( $description->type == 3 ) { $description = $description->content; } */ // } }break; } } print( "The persons firstname is: $firstName <br>" ); print( "The persons lastname is: $lastName <br>" ); print( "The persons description is: $description <br>" ); } } } } ?>