Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Using PHP to parse specific XML tag content? >Thread Next - Re: Using PHP to parse specific XML tag content? Re: Using PHP to parse specific XML tag content?To: NULL Date: 12/2/2008 8:07:00 AM On Dec 2, 9:14=A0am, Mechphisto <mechphi...@gmail.com> wrote:
[..snip all..]
Based on the fact the above works, it's just not doing exactly what I
want, I tried the following adjustments to the PHP.
Logically, I don't see any reason why it's not working, but it's
simply not displaying anything on the echo's.
Any ideas?
<?php
$file =3D "xml_test.xml";
function startTag($parser, $data){
global $msg1;
global $msg2;
global $current;
$current =3D $data;
if ($current =3D=3D "message1") {
$msg1 .=3D "<b>";
return $msg1;
} elseif ($current =3D=3D "message2") {
$msg2 .=3D "<em>";
return $msg2;
}
}
function endTag($parser, $data){
global $msg1;
global $msg2;
if ($data =3D=3D "message1") {
$msg1 .=3D "</b>";
return $msg1;
} elseif ($data =3D=3D "message2") {
$msg2 .=3D "</em>";
return $msg2;
}
}
function contents($parser, $data){
global $msg1;
global $msg2;
global $current;
if ($current =3D=3D "message1") {
$msg1 .=3D $data;
return $msg1;
} elseif ($current =3D=3D "message2") {
$msg2 .=3D $data;
return $msg2;
}
}
$xml_parser =3D xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "contents");
$fp =3D fopen($file, "r");
$data =3D fread($fp, 80000);
if(!(xml_parse($xml_parser, $data, feof($fp)))){
die("Error on line " . xml_get_current_line_number($xml_parser));
}
xml_parser_free($xml_parser);
fclose($fp);
echo $msg1;
echo $msg2;
?>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
