Total members 11390 |It is currently Sun Dec 21, 2014 12:38 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R

All times are UTC [ DST ]



  php SAX parser in action
Sun Oct 26, 2008 6:46 pm 

php code
<?
function start_element($parser, $element_name, $element_attrs) {
switch ($element_name) {
case 'KEYWORDS':
echo '<h1>Keywords</h1><ul>';
break;
case 'KEYWORD':
echo '<li>';
break;
}
}

function end_element($parser, $element_name) {
switch ($element_name) {
case 'KEYWORDS':
echo '</ul>';
break;
case 'KEYWORD':
echo '</li>';
break;
}
}


function character_data($parser, $data) {
echo htmlentities($data);
}

$parser = xml_parser_create();
xml_set_element_handler($parser, 'start_element', 'end_element');
xml_set_character_data_handler($parser, 'character_data');

$fp = fopen('keyword-data.xml', 'r')
or die ("Cannot open keyword-data.xml!");


while ($data = fread($fp, 4096)) {
xml_parse($parser, $data, feof($fp)) or
die(sprintf('XML ERROR: %s at line %d',
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}


xml_parser_free($parser);
?>

keyword-data.xml
xml code
<!-- keyword-data.xml  -->
<keywords>
<keyword>XML</keyword>
<keyword>PHP</keyword>
<keyword>Perl</keyword>
<keyword>JavaScript</keyword>
<keyword>ASP</keyword>
</keywords>


_________________
Please recommend / share my post if you found it helpful.


Author:
Mastermind
User avatar Posts: 2694
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : php SAX parser in action
 php simple XML parser     -  
 Command Line Parser Code Using C++     -  
 How to implement Command Line Parser in C++ Code     -  
 php extends in action     -  
 is_numeric in action     -  
 JButtons implementing an Action     -  
 Button action listener should implement abstract method     -  
 Two Listeners- Mutli- Action Listeners on Text Area     -  

All times are UTC [ DST ]



Topic Tags

PHP XML






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team