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 :
function tag_contents($parser, $data) {
echo "Contents : ".$data."<br />";
}
Once the function is written, we can setup the parser to use it :
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.