Home >Backend Development >PHP Tutorial >PHP and XML: Using the expat function (3)

PHP and XML: Using the expat function (3)

黄舟
黄舟Original
2016-12-17 09:43:18929browse

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 our The actual link to the 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
Defining simple tags for the XML parser
Setting simple options for the XML parser
To XML parser registration callback function
Use XML parser through a PHP class
Use PHP class in another script

The above is the content of PHP and XML: using expat function (3). For more related articles, please pay attention to PHP Chinese Net (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn