Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Group info
Members: 21
Language: English
Group categories:
Computers > Databases
Computers > Programming
Computers
More group info »
Recent pages and files
php-and-xml-2-processing-xml-documents    

In the previous part of this tutorial, we looked at what XML is, andhow to create a valid XML file. In this tutorial, we're going to lookat processing XML documents. First, we are going to look at thedifferent methods of processing XML, using either SAX or DOM.

Weare then going to look in more detail at the SAX method of processing,creating an XML file to work with, and then creating the PHP coderequired to translate the XML into HTML so that it can be displayed inany browser.
SAX or DOM

There are two methods of processing XML using PHP ? SAX or DOM ? and these methods process the XML in different ways.
SAX

SAXstands for Simple API for XML and is mainly used for interpreting largeXML documents. The SAX method reads through the document a tag at atime and calls an event handler each time it comes across an open tag,a closed tag, or data in between the two tags.

Because the SAXmethod doesn't read the whole document in one go, it can be used forlarge documents which may not fit in the computer's memory all at theone time, and so is the most commonly used method. The downside is thatthere are limits to how it can process the XML, because it only reads asmall part of the document at a time.
DOM

DOM stands forDocument Object Model and allows PHP to access and manipulate XMLdocuments. Instead of reading the XML document in small sections likethe SAX method, it reads the whole document in one go, and representsthe document as a tree structure. Because the whole document isanalysed in one go, it allows you to move up and down through the tree,rather than just being limited to reading the document from start tofinish.

You can also create new XML documents and change valuesin existing documents, which you can't do with the SAX method. The onlydownside of this method of processing is that you need more memory toread in large documents, although this isn't a problem with smalldocuments.

In this tutorial we're going to look at processing XML using the SAX method.
PHP Requirements

Inorder to process XML using the SAX method on PHP you need to make surethat the XML extensions are available for your version of PHP. If youare on Windows, you can do this by editing the php.ini file anduncommenting the various PHP XML extensions (such asextension=php_domxml.dll) by removing the semicolon from the front ofthe line. You will then need to restart your web server so the newextensions take effect.

On Linux the process is morecomplicated, and you will need to recompile PHP and include therelevant PHP XML extensions. To find out more about this consult theXML and Installation sections of the online PHP manual athttp://www.php.net/.

If you are using your web host's server,you will need to check with your host that XML is enabled, and ask themto enable it for you if it's not.

FOR FULL ARTICLE ... CLICK HERE~!@

Version: 
Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google