In this example, the PHP file reads and displays the xml file content.
The content of the PHP file is as follows. Put the php file and slashdot. xml in the same folder.
<? Php
$ Open_tags = array (
'Story' => '<STORY> ',
'Title' => '<TITLE> ',
'URL' => '<URL> ',
'Author' => '<AUTHOR>'
);
$ Close_tags = array (
'Story' => '</STORY> ',
'Title' => '</TITLE> ',
'URL' => '</URL> ',
'Author' => '</AUTHOR>'
);
?>
<? Php
// The following is the definition function to extract data:
// Processing start tag attributes refer
// $ Attrs is a multi-dimensional array. The key value is the attribute name and the value is the value of this attribute.
Function startElement ($ parser, $ name, $ attrs = ''){
Global $ open_tags, $ temp, $ current_tag;
$ Current_tag = $ name;
If ($ format = $ open_tags [$ name]) {
Switch ($ name ){
Case 'store ':
Echo 'new story :';
Break;
Default:
Break;
}
}
}
// $ Current_tag indicates the tag being processed, which will be used in the characterData function.
//
// When we encounter the </STORY> Mark, we know that we need to flush all the temporary variables to prepare for the next mark.
<Lt;/STORY> ',
'Title' => '</TITLE> ',
'URL' => '</URL> ',
'Author' => '</AUTHOR>'
);
?>
<? Php
// The following is the definition function to extract data:
// Processing start tag attributes refer
// $ Attrs is a multi-dimensional array. The key value is the attribute name and the value is the value of this attribute.
Function startElement ($ parser, $ name, $ attrs = ''){
Global $ open_tags, $ temp, $ current_tag;
$ Current_tag = $ name;
If ($ format = $ open_tags [$ name]) {
Switch ($ name ){
Case 'store ':
Echo 'new story :';
Break;
Default:
Break;
}
}
}
// $ Current_tag indicates the tag being processed, which will be used in the characterData function.
//
// When we encounter the </STORY> Mark, we know that we need to flush all the temporary variables to prepare for the next mark.
Function endElement ($ parser, $ name, $ attrs = ''){
Global $ close_tags, $ temp, $ current_tag;
If ($ format = $ close_tags [$ name]) {
Switch ($ name ){
Case 'store ':
Return_page ($ temp );
$ Temp = '';
Break;