Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Your Email:

Parsing XML using PHP4

By Burhan Khalid
2005-08-16


Setting up content (data) handlers

We have taken care of our starting and ending tags, so now we must deal with the acutal content of a tag. The xml_set_character_data_handler function sets up the character data handling functions for the parser. Since we know that our data is going to be character based, we will use this function. There are different xml_set functions for different types of data. You can view the list of different data handler functions in the php manual.

The xml_set_character_data_handler function takes two arguments. One is a handle to the parser, and the other is the name of the function to call for character data. Like the opening and closing tag functions, we have to write the character data handling function. Our function must accept these two arguments $parser, $data :

PHP:

  1. function tag_contents($parser, $data) {
  2.    echo "Contents : ".$data."<br />";
  3. }

Once the function is written, we can setup the parser to use it :

PHP:
  1. xml_set_character_data_handler($xmlparser, "tag_contents");

Our functions will just print out the information about our tag. We will later modify them so that we can acutally do something useful with our information. At this stage we just want to check to make sure that our parser is working correctly.



Tutorial Pages:
» Parsing XML using PHP4
» XML File Structure
» Creating our XML File
» Parsing with PHP
» Creating our Parser
» Setting up tag handlers
» Setting up content (data) handlers
» Starting up the parser
» Creating the gallery


© 2004-2005 Burhan Khalid


 | Bookmark
Related Tutorials:
» Port Scanning and Service Status Checking in PHP
» Web Database Access from Desktop Applications
» CubeCart 3.0 Installation and Configuration
» PHP Site Search Made Easy
» Installing and Configuring Drupal 6.1
» Desktop Application Development with PHP-GTK