#native_company# #native_desc#
#native_cta#

Converting XML into a PHP data structure Page 9

By PHP Builder Staff
on December 25, 2002

>How To Use The Class

The XMLToArray class we just built is rather simple in function. It
parses your XML document into a multidimensional array. Here is some
code that shows you how you might use this now:

<?php

require_once("XMLToArray.php");

$xml2a      = new XMLToArray();

$root_node  $xml2a->parse($xml_text);

$drive      array_shift($root_node["_ELEMENTS"]);

//print('&lt;pre&gt;'); print_r($drive); print('&lt;/pre&gt;');

// print all the folders...

foreach ($drive["_ELEMENTS"] as $folder) {

    
printf("FOLDER: %sn"$folder["name"]);

    // print all the files in this folder

    
foreach ($folder["_ELEMENTS"] as $file) {

        
printf("tFILE: %sn"$file["name"]);

    }

}

?>



The output of this code would yield a display similar to the following:
FOLDER: folder01
	FILE: a.txt
	FILE: b.txt
FOLDER: folder02
	FILE: c.txt
	FILE: d.txt

1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|