blear Posted November 17, 2006 Share Posted November 17, 2006 This is the code that activates and calls the parser:[code]$xmlFile = fopen($xmlFileName,'r');xml_set_character_data_handler($reader,"char");xml_set_element_handler($reader,"AODFindBeg","charEnd");xml_parser_set_option($reader, XML_OPTION_CASE_FOLDING, false); while ($data=fread($xmlFile,4096)){ xml_parse($reader,$data,feof($xmlFile)) or die (sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($reader)), xml_get_current_line_number($reader))); } xml_parser_free($reader);[/code]These are the parser functions I use[code]//Begining tag handlerfunction AODFindBeg($reader,$eleName,$attrib){ if((strtolower($eleName)=='results')) xml_set_character_data_handler($reader,"ReportResult"); else if((strtolower($eleName)=='date')) xml_set_character_data_handler($reader,"ReportDate"); else if((strtolower($eleName)=='name')) xml_set_character_data_handler($reader,"ReportName"); else if((strtolower($eleName)=='note_id')) xml_set_character_data_handler($reader,"ReportNoteID"); else if((strtolower($eleName)=='universal_id')) xml_set_character_data_handler($reader,"ReportUniversalID"); else if((strtolower($eleName)=='language')) xml_set_character_data_handler($reader,"ReportLanguage");//End tag handlerfunction charEnd($reader,$eleName){ if((strtolower($eleName)=='report')) echo "</TR>\n"; else if((strtolower($eleName)=='database')) echo "</TABLE>\n"; }// Element handlers function ReportResult($reader,$data){ echo "<TD>$data</TD>\n"; }function ReportDate($reader,$data){ echo "<TD>$data</TD>\n"; }function ReportName($reader,$data){ echo "<TD>$data</TD>\n"; }function ReportNoteID($reader,$data){ echo "<TD>$data</TD>\n"; }function ReportUniversalID($reader,$data){ echo "<TD>$data</TD>\n"; }function ReportLanguage($reader,$data){ echo "<TD>$data</TD>\n"; }[/code]Now, my problem is that for every begin and end element, I get an extra TD /TD in my table rows. It seems that the parser puts out $data=chr(13).chr(10)." " at each begin and/or end. Can anyone tell me how to prevent this from happening? Quote Link to comment https://forums.phpfreaks.com/topic/27622-xml-parser-adds-extra-elements/ Share on other sites More sharing options...
blear Posted November 18, 2006 Author Share Posted November 18, 2006 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/27622-xml-parser-adds-extra-elements/#findComment-126521 Share on other sites More sharing options...
blear Posted November 21, 2006 Author Share Posted November 21, 2006 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/27622-xml-parser-adds-extra-elements/#findComment-127971 Share on other sites More sharing options...
ToonMariner Posted November 21, 2006 Share Posted November 21, 2006 are the extra <td></td> inside the holder you have created? if so just remove your <TD></TD> tags in your function... Quote Link to comment https://forums.phpfreaks.com/topic/27622-xml-parser-adds-extra-elements/#findComment-127975 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.