PHP and XML: Using the Expat function (iii)

Source: Internet
Author: User
Tags xml parser
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)!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.