Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Protung Dragos  >  PHP Simple Large XML Parser  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Simple Large XML Parser
Parse XML documents and return arrays of elements
Author: By
Last change: Update of example code for the new version
Date: 5 years ago
Size: 1,869 bytes
 

Contents

Class file image Download
<?php

require_once('SimpleLargeXMLParser.class.php');

$xml dirname(__FILE__)."/example.xml";
//$xml = "http://www.protung.ro/feed/atom/"; // parse an Atom feed


// create a new object
$parser = new SimpleLargeXMLParser();
// load the XML
$parser->loadXML($xml);


//$array = $parser->parseXML("//myFirstNode/color-palettes/color[@type='hex']"); // get all colors in hex format
//$array = $parser->parseXML("//myFirstNode/first-100-numbers/number[@n>'50']"); // get all numbers bigger then 50
//$array = $parser->parseXML("//myFirstNode/searchengines"); // get all search engines
//$array = $parser->parseXML("//myFirstNode"); // get all XML file
//$array = $parser->parseXML("*/*[@type='html']"); // use wilde cards to get all nodes that match a criteria
$array $parser->parseXML(); // get all XML file - faster if you specify the first node


// in case you also need the attibutes (with values) you need to pass the 2rd parameter as true
// the array structure will change in this case 
//$array = $parser->parseXML("//myFirstNode/color-palettes/color[@type='hex']", true); // get all colors in hex format
//$array = $parser->parseXML("//myFirstNode/first-100-numbers/number[@n>'50']", true); // get all numbers bigger then 50
//$array = $parser->parseXML("//myFirstNode/searchengines", true); // get all search engines
//$array = $parser->parseXML("*/*[@type='html']", true); // use wilde cards to get all nodes that match a criteria
//$array = $parser->parseXML("//myFirstNode", true); // get all XML file




// in case you have special XML files (like RSS or Atom feeds) you need to register the namespaces
//$parser->registerNamespace("atom", "http://www.w3.org/2005/Atom"); // register the namespace
//$array = $parser->parseXML("//atom:feed/atom:entry"); //


print "<pre>";
print_r($array);
print 
"</pre>";

?>