Using XML in php easy way |
If you ever plan to use XML with PHP there is good XMLParser class written by Adam A Flynn. You can get it for PHP4 and PHP5 from his page http://www.phppal.com/xml/doc.php. There are some examples, so it wont be very hard to understand.
UPDATE: seemes, that www.phppal.com is dead allready :/
You can download the class from my page: XMLParser.zip To use this class simply copy it in /usr/lib/php directory or if you dont have root permissions, copy in the same folder as your php script.
I had some problems at first, because I was not familiar with data structure after parsing, so I used such code to view, how objects and arrays was formed:
<?php
//Require XMLParser class
//If XMLParser.php class is in same dir as php script use this:
//require("./XMLParser.php");
require("XMLParser.php");
//Get the XML document loaded into a variable
$xml = file_get_contents('test.xml');
//Set up the parser object
$parser = new XMLParser($xml);
//Work the magic...
$parser->Parse();
//Print all xml children array structure
print_r($parser->document->tagChildren);
?>
That's all. It is much simplier than i thought to work with XML :) More info at php documentation: http://lt.php.net/manua/en/ref.xml.php




