PHP and XML: Use the expat function (1)

Source: Internet
Author: User

PHP and XML: Use the expat function (1)

Extensible Markup Language is clearly something that most developers will want to add to their toolbox. XML is a W3C standard. It is open, language-neutral, API-neutral, stream, text, and human-readable, it is also a way to bring structured data to the web. XML is a subset of SGML. It is not an identity language, but it allows the authors to define their own identity language to maintain better consistency with hierarchical data.

Now, using PHP to analyze XML documents is not a very deep topic I have seen on the web and other places. Some useful information for XML analysis functions has been provided in the PHP manual, but this seems to be all the information I can find. Other languages seem to have more XML Information and working examples than PHP, so in this article, I will try to make part of my effort to change this situation.

I will lead the reader to experience a fairly simple XML application, which is the implementation of the news system for my website. I did use this application on my website, and now it works well. If you like it, you can use it freely. Okay, let's get started!

To make XML analysis functions effective in PHP, you need a module that supports XML on your web server. This means that you may have to re-compile your module to support XML. For more information, see here. XML analysis functions are actually included in a SAX analyzer expat, which provides simple functions about XML. Another analyzer is DOM analyzer, which is easier to use. One example of this analyzer is Microsoft's MSXML analyzer component, it allows programmers to manipulate a tree-like object to process nodes and elements. The expat analyzer (or any SAX analyzer) allows you to analyze an XML document by specifying a callback function for different tag types during XML document analysis. When the analyzer analyzes your XML document and encounters a tag, it will call your function and your function will process the specific tag before it continues to run. You can think of it as an event-driven method.

Let's take a look at an XML document that uses the 'newsboy 'class for analysis.

Mynews. xml

Sooo Busy!

I haven't posted anything here for a while now as I have been busy with work (have to pay those
Bills !).
I have just finished a neat little script that stores a complete record set in a session
Variable after
Doing an SQL query. The neat part is that an XML doc is stored in the session variable
An when paging
Through the results (often near 1000 !) The script displays 50 results at a time from
XML doc in
Session variable instead of doing another query against the database. It takes a BIG load
Off of
Database server.

NewsBoy Class

Converted Newsboy to a PHP class to allow better publish action (as far as PHP allows .)

Guess that means this is version 0.02 ?!
Newsboy will have a section of it's own soon on how to use and customize the class.

NewsBoy is up!

I have just finished NewsBoy v0.01 !!!
It looks quite promising. You may ask, "" What the heck is it ?! ".

Well it's a simple news system for web-sites, written in PHP, that makes use of XML
The news data format allowing easy updating and portability between platforms.
It uses the built in expat parser for Apache.
This is just the very first version and there will be loads of improvements as
Project progresses.

Romeo must Die

Saw a really cool movie today at Mann called 'Romeo must die'
Nice fight scenes for a typical kung-fu movie with some 'matrix 'style effects.

One particle cool effect was the 'X-Ray Vision 'effect that occured in various
Fight scenes.
The hero, played by Jet Li, strikes a bad guy and you can see the bone in his arm
Crack in X-RAY vision.
There were some funny scenes too when Jet has to play American football with
Bad guys.
The official website for the movie is <a href = 'HTTP: //'
> Here </A> "WIDTH = 300>

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: 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.