SAX 实现对XML文档的读写
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?php
$parse=xml_parser_create('utf-8');
xml_set_element_handler($parse,'star','ends');
function star($parse,$a,$b){
//echo "开始标签:".$a."<br>";
}
function ends($parse,$a){
//echo "结束标签:".$a."<br>";
}
xml_set_character_data_handler($parse,'fun');
function fun($parse,$a){
//echo '遇到的数据'.$a;
echo $a;
}
$xml_data=file_get_contents('mysql_xml.xml');
$tr=xml_parse($parse,$xml_data,true);
if($tr){
echo "解析成功";
}else{
$err=xml_error_string(xml_get_error_code());
echo "有错误";
}
?>
</body>
</html>