PHP and XML: Using the Expat function (iii)
How do I use this class in a PHP script? is actually very simple. Here's an example:
First the class definition needs to be included in the script
Require (Class_dir. " Class. Newsboy.php ");
We then create an instance of the class and set the actual link to the file for 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 parser to parse the document.
$news->parse ();
Then we print the HTML to the screen.
Print ($news->html);
Also, the class must be freed at the end of completion.
$news->destroy ();
That's all you have to do.
Section
In this short document, we covered the process of using PHP to process xml:
A simple XML document structure
To define a simple tag for the XML parser
Set simple options for the XML parser
Registering a callback function with the XML parser
Using a PHP class to use the XML parser
Using the PHP class in another script
The above is PHP and XML: Use the Expat function (c) content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!