PHP and XML: Using expat function (3)
How to use this class in a PHP script? It's actually very simple. Here is an example:
First the class definition needs to be included in the script
require (CLASS_DIR."class.Newsboy.php");
Then, We create an instance of the class and set the fileness to the actual link to our XML document.
$news = new newsboy();
$news->xml_file = "xml/mynews.xml";
or
$news-> xml_file = "http://xmldocs.mysite.com/mynews.xml"
Then we call the analyzer to analyze the document.
$news->parse();
Then we print the html to the screen.
print ($news->html);
And, at the end, the class must be released when completed.
$news->destroy();
That’s all there is to do.
Section
In this short document, we cover the process of processing XML using PHP:
Simple XML document structure
for XML parser Define simple tags
Set simple options for the XML parser
Register a callback function with the XML parser
Use the XML parser through a PHP class
Use the PHP class in another script