Documentation
Tutorials
Parsing XML with Vigilante
Vigilante parses XML with a class based on the Amazon PHP API by Calin Uioreanu. This class, simply named xml, handles almost every function required to parse XML except parser creation and the end element handler. You must first extend the xml class with your own custom class to include:
- A constructor which sets the
$parserproperty to create a parser. - An end handler method.
As an example, Vigilante includes a class named rss,
which parses RSS feeds. Example 2-6-1 demonstrates how Vigilante that feed.
Example 2-6-1
//Instantiate an RSS object.
$rss = new rss;
//Get a file pointer resource with the following URL, but timeout after 20 seconds.
$rss->setInputUrl('http://www.mysite.com/index.xml', 20);
//Parse the RSS feed.
$show_feed = $rss->parse();
//If the parsing is successful, display the results.
if ($show_feed==true)
{
[ ...display RSS feed... ]
}
For more information on extending Vigilante's XML class, see Extending the xml class.